Cleaning up embedded objects on box delete
authorAlexander Ebert <ebert@woltlab.com>
Sun, 18 Mar 2018 14:29:48 +0000 (15:29 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 18 Mar 2018 14:29:48 +0000 (15:29 +0100)
wcfsetup/install/files/lib/data/box/BoxAction.class.php

index 72b768bf3964bf6bdbb461d732c3025149f3c3e2..4313253aabf44f63b15bd0c89806359deb624d1f 100644 (file)
@@ -228,17 +228,25 @@ class BoxAction extends AbstractDatabaseObjectAction {
         * @inheritDoc
         */
        public function delete() {
+               $boxContentIDs = [];
                foreach ($this->getObjects() as $box) {
-                       if ($box->boxType == 'tpl') {
-                               foreach ($box->getBoxContents() as $languageID => $content) {
+                       foreach ($box->getBoxContents() as $languageID => $content) {
+                               if ($box->boxType == 'tpl') {
                                        $file = WCF_DIR . 'templates/' . $box->getTplName(($languageID ?: null)) . '.tpl';
                                        if (file_exists($file)) {
                                                @unlink($file);
                                        }
                                }
+                               
+                               $boxContentIDs[] = $content->boxContentID;
                        }
                }
                
+               if (!empty($boxContentIDs)) {
+                       // update embedded objects
+                       MessageEmbeddedObjectManager::getInstance()->removeObjects('com.woltlab.wcf.box.content', $boxContentIDs);
+               }
+               
                parent::delete();
        }