page-PIP didn't handle import/delete of type tpl correctly
authormutec <webmaster@mysterycode.de>
Sun, 15 Oct 2017 13:47:31 +0000 (15:47 +0200)
committermutec <webmaster@mysterycode.de>
Sun, 15 Oct 2017 13:47:31 +0000 (15:47 +0200)
the PIP didn't generate the template-file during the import and didn't remove it if the page get's deleted

wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php

index f47bbf9a533bcdb3191fa17814476783d625415a..2158027c09ccb6e2104f459f266b70e61dc143cf 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system\package\plugin;
 use wcf\data\package\PackageCache;
 use wcf\data\page\Page;
+use wcf\data\page\PageAction;
 use wcf\data\page\PageEditor;
 use wcf\system\exception\SystemException;
 use wcf\system\language\LanguageFactory;
@@ -38,19 +39,16 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
         * @inheritDoc
         */
        protected function handleDelete(array $items) {
-               $sql = "DELETE FROM     wcf".WCF_N."_page
-                       WHERE           identifier = ?
-                                       AND packageID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               
-               WCF::getDB()->beginTransaction();
+               $pages = [];
                foreach ($items as $item) {
-                       $statement->execute([
-                               $item['attributes']['identifier'],
-                               $this->installation->getPackageID()
-                       ]);
+                       $page = Page::getPageByIdentifier($item['attributes']['identifier']);
+                       if ($page !== null && $page->pageID && $page->packageID == $this->installation->getPackageID()) $pages[] = $page;
+               }
+               
+               if (!empty($pages)) {
+                       $pageAction = new PageAction($pages, 'delete');
+                       $pageAction->executeAction();
                }
-               WCF::getDB()->commitTransaction();
        }
        
        /**
@@ -316,6 +314,12 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                                                $content['metaKeywords'],
                                                $content['customURL']
                                        ]);
+                                       
+                                       // generate template if page's type is 'tpl'
+                                       $page = new Page($pageID);
+                                       if ($page->pageType == 'tpl') {
+                                               file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']);
+                                       }
                                }
                        }
                        WCF::getDB()->commitTransaction();