mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Improved deleting flex objects
This commit is contained in:
parent
e8bc5fac71
commit
def437e42b
|
|
@ -14,6 +14,7 @@ namespace Grav\Common\Flex;
|
|||
use Grav\Common\Flex\Traits\FlexGravTrait;
|
||||
use Grav\Common\Flex\Traits\FlexObjectTrait;
|
||||
use Grav\Common\Media\Interfaces\MediaInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaUploadInterface;
|
||||
use Grav\Framework\Flex\Traits\FlexMediaTrait;
|
||||
use function is_array;
|
||||
|
||||
|
|
@ -71,4 +72,20 @@ abstract class FlexObject extends \Grav\Framework\Flex\FlexObject implements Med
|
|||
|
||||
return parent::prepareStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function doDelete(): void
|
||||
{
|
||||
$fields = $this->getMediaFields();
|
||||
foreach ($fields as $field) {
|
||||
$media = $this->getMediaField($field);
|
||||
if ($media instanceof MediaUploadInterface) {
|
||||
$media->deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
parent::doDelete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -824,20 +824,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
|||
|
||||
$this->triggerEvent('onBeforeDelete');
|
||||
|
||||
$this->getFlexDirectory()->getStorage()->deleteRows([$this->getStorageKey() => $this->prepareStorage()]);
|
||||
|
||||
try {
|
||||
$this->getFlexDirectory()->reloadIndex();
|
||||
if (method_exists($this, 'clearMediaCache')) {
|
||||
$this->clearMediaCache();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = Grav::instance()['debugger'];
|
||||
$debugger->addException($e);
|
||||
|
||||
// Caching failed, but we can ignore that for now.
|
||||
}
|
||||
$this->onDelete();
|
||||
|
||||
$this->triggerEvent('onAfterDelete');
|
||||
|
||||
|
|
@ -1050,6 +1037,38 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
|||
$this->setElements($serialized['elements']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function doDelete(): void
|
||||
{
|
||||
$this->getFlexDirectory()->getStorage()->deleteRows([$this->getStorageKey() => $this->prepareStorage()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function onDelete(): void
|
||||
{
|
||||
$this->doDelete();
|
||||
|
||||
try {
|
||||
// Force reload object index.
|
||||
$this->getFlexDirectory()->reloadIndex();
|
||||
|
||||
// Clear media cache.
|
||||
if (method_exists($this, 'clearMediaCache')) {
|
||||
$this->clearMediaCache();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = Grav::instance()['debugger'];
|
||||
$debugger->addException($e);
|
||||
|
||||
// Caching failed, but we can ignore that for now.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user