Giter Site home page Giter Site logo

Media preview image deletion issue about sulu HOT 3 OPEN

nikomuse avatar nikomuse commented on June 9, 2024
Media preview image deletion issue

from sulu.

Comments (3)

llefort001 avatar llefort001 commented on June 9, 2024

I am having the same problem with Entities having a relationship with a media entity.

If you try to remove a linked media, integrity constraint will pop and refuse to remove media, but it is too late, file has been deleted.
Then, as you said, media still exists but file doesn't, which makes unable to delete media forever (with admin interface).

Solution would be to check integrity constraint BEFORE deleting the file

from sulu.

llefort001 avatar llefort001 commented on June 9, 2024

Depending on your implementation, you may use these annotations to unlink media from your custom entity onDelete:

/**
* @Orm\OneToOne(targetEntity=Media::class)
* @Orm\JoinColumn(onDelete="SET NULL")
*/

/**
* @Orm\ManyToOne(targetEntity=Media::class)
* @Orm\JoinColumn(name="media_id", referencedColumnName="id", onDelete="SET NULL")
*/

/**
* @Orm\OneToMany(targetEntity=ExampleEntityMedia::class, mappedBy="example_entity", orphanRemoval=true, cascade={"persist", "remove"})
* @Orm\OrderBy({"position" = "ASC"})
* @Orm\JoinColumn(name="example_entity_id", referencedColumnName="id", onDelete="CASCADE")
*/

from sulu.

mamazu avatar mamazu commented on June 9, 2024

Wouldn't it maybe make sense to swap the deletion from the database and the file system removal. So that if the constraint gets triggered the media doesn't get deleted?

from sulu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.