Fixed application management during setup
authorAlexander Ebert <ebert@woltlab.com>
Wed, 5 Dec 2012 00:47:33 +0000 (01:47 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 5 Dec 2012 00:47:33 +0000 (01:47 +0100)
wcfsetup/install/files/lib/data/application/ApplicationAction.class.php
wcfsetup/install/files/lib/data/application/ApplicationEditor.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php

index 81dbf456ab2798dd2ecdd37c16ac5b1c92079dcd..ad7573785f92c0b4d678457dc7f96e36fc168165 100644 (file)
@@ -33,8 +33,7 @@ class ApplicationAction extends AbstractDatabaseObjectAction {
                
                $sql = "UPDATE  wcf".WCF_N."_application
                        SET     cookieDomain = ?,
-                               cookiePath = ?,
-                               isPrimary = ?
+                               cookiePath = ?
                        WHERE   packageID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                
@@ -80,7 +79,6 @@ class ApplicationAction extends AbstractDatabaseObjectAction {
                                $statement->execute(array(
                                        $domainName,
                                        $path,
-                                       $isPrimary,
                                        $packageID
                                ));
                        }
index f7825e574121f3ba11ae26a88c8df6884e045b05..696a95703ce8b0bfd05653b7636107e28ae7659a 100644 (file)
@@ -1,6 +1,9 @@
 <?php
 namespace wcf\data\application;
 use wcf\data\DatabaseObjectEditor;
+use wcf\data\IEditableCachedObject;
+use wcf\system\cache\CacheHandler;
+use wcf\system\WCF;
 
 /**
  * Provides functions to edit applications.
@@ -12,9 +15,74 @@ use wcf\data\DatabaseObjectEditor;
  * @subpackage data.application
  * @category   Community Framework
  */
-class ApplicationEditor extends DatabaseObjectEditor {
+class ApplicationEditor extends DatabaseObjectEditor implements IEditableCachedObject {
        /**
         * @see wcf\data\DatabaseObjectDecorator::$baseClass
         */
        protected static $baseClass = 'wcf\data\application\Application';
+       
+       /**
+        * Sets current application as primary application.
+        */
+       public function setAsPrimary() {
+               $sql = "UPDATE  wcf".WCF_N."_application
+                       SET     isPrimary = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(0));
+               
+               $sql = "UPDATE  wcf".WCF_N."_application
+                       SET     isPrimary = ?
+                       WHERE   applicationID = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       1,
+                       $this->applicationID
+               ));
+               
+               self::resetCache();
+       }
+       
+       /**
+        * Sets the first installed application as primary unless an other application already is primary.
+        */
+       public static function setup() {
+               $sql = "SELECT  COUNT(*) AS count
+                       FROM    wcf".WCF_N."_application
+                       WHERE   isApplication = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(1));
+               $row = $statement->fetchArray();
+               
+               if ($row['count']) {
+                       // there is already a primary application
+                       return;
+               }
+               else {
+                       // set first installed application as primary
+                       $sql = "SELECT          packageID
+                               FROM            wcf".WCF_N."_package
+                               WHERE           packageID <> ?
+                                               AND isApplication = ?
+                               ORDER BY        installDate ASC";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array(
+                               1,
+                               1
+                       ));
+                       $row = $statement->fetchArray();
+                       
+                       $sql = "UPDATE  wcf".WCF_N."_application
+                               SET     isApplication = ?
+                               WHERE   packageID = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($row['packageID']));
+               }
+       }
+       
+       /**
+        * @see wcf\data\IEditableCachedObject::resetCache()
+        */
+       public static function resetCache() {
+               CacheHandler::getInstance()->clear(WCF_DIR.'cache/', 'cache.application.php');
+       }
 }
index 7b9c25477caef37b14659bb7980165844b710124..30bdd90fc5166937ea6fa957ff63cc6ef9429e89 100644 (file)
@@ -145,6 +145,7 @@ class PackageInstallationDispatcher {
                                
                                // rebuild application paths
                                ApplicationHandler::rebuild();
+                               ApplicationEditor::setup();
                        }
                }