[COMPONENT][Link] Remove relation to note when note is removed
Moved entity NoteToLink to the component
This commit is contained in:
parent
dcc867dad7
commit
dcc37b055d
@ -17,7 +17,7 @@
|
|||||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
namespace App\Entity;
|
namespace Component\Link\Entity;
|
||||||
|
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Core\Entity;
|
use App\Core\Entity;
|
||||||
@ -93,6 +93,53 @@ class NoteToLink extends Entity
|
|||||||
return parent::create($args, $obj);
|
return parent::create($args, $obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $note_id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function removeWhereNoteId(int $note_id): mixed
|
||||||
|
{
|
||||||
|
return DB::dql(
|
||||||
|
<<<'EOF'
|
||||||
|
DELETE FROM note_to_link ntl
|
||||||
|
WHERE ntl.note_id = :note_id
|
||||||
|
EOF,
|
||||||
|
['note_id' => $note_id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $link_id
|
||||||
|
* @param int $note_id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function removeWhere(int $link_id, int $note_id): mixed
|
||||||
|
{
|
||||||
|
return DB::dql(
|
||||||
|
<<<'EOF'
|
||||||
|
DELETE FROM note_to_link ntl
|
||||||
|
WHERE (ntl.link_id = :link_id
|
||||||
|
OR ntl.note_id = :note_id)
|
||||||
|
EOF,
|
||||||
|
['link_id' => $link_id, 'note_id' => $note_id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $link_id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function removeWhereLinkId(int $link_id): mixed
|
||||||
|
{
|
||||||
|
return DB::dql(
|
||||||
|
<<<'EOF'
|
||||||
|
DELETE FROM note_to_link ntl
|
||||||
|
WHERE ntl.link_id = :link_id
|
||||||
|
EOF,
|
||||||
|
['link_id' => $link_id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function schemaDef(): array
|
public static function schemaDef(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
@ -27,9 +27,9 @@ use App\Core\DB\DB;
|
|||||||
use App\Core\Event;
|
use App\Core\Event;
|
||||||
use App\Core\Modules\Component;
|
use App\Core\Modules\Component;
|
||||||
use App\Entity\Note;
|
use App\Entity\Note;
|
||||||
use App\Entity\NoteToLink;
|
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
use App\Util\HTML;
|
use App\Util\HTML;
|
||||||
|
use Component\Link\Entity\NoteToLink;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class Link extends Component
|
class Link extends Component
|
||||||
@ -258,4 +258,10 @@ class Link extends Component
|
|||||||
|
|
||||||
return HTML::html(['a' => ['attrs' => $attrs, $url]], options: ['indent' => false]);
|
return HTML::html(['a' => ['attrs' => $attrs, $url]], options: ['indent' => false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onNoteDeleteRelated(Note &$note): bool
|
||||||
|
{
|
||||||
|
NoteToLink::removeWhereNoteId($note->getId());
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user