/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
	 */
	public function install() {
		parent::install();
		
		// get package installation dir
		$dir = $this->installation->getPackage()->packageDir;
		if (empty($dir)) {
			if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install') {
				// application
				// prompt package dir
				$dir = $this->promptPackageDir();
			}
			
			// save package dir
			if (!empty($dir)) {
				$package = new Package($this->installation->getPackageID());
				$packageEditor = new PackageEditor($package);
				$packageEditor->update(array('packageDir' => $dir));
				
				$this->installation->getPackage()->packageDir = $dir;
			}
		}
		
		// absolute path to package dir
		$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$dir));
		
		// extract files.tar to temp folder
		$sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'files_');
		
		// create file handler
		$fileHandler = new FilesFileHandler($this->installation);
		
		// extract content of files.tar
		$fileInstaller = $this->installation->extractFiles($packageDir, $sourceFile, $fileHandler);
		
		// if this a an application, write config.inc.php for this package
		if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install') {
			// touch file
			$fileInstaller->touchFile(PackageInstallationDispatcher::CONFIG_FILE);
			
			// create file
			Package::writeConfigFile($this->installation->getPackageID());
			
			// log file
			$sql = "INSERT INTO	wcf".WCF_N."_package_installation_file_log
						(packageID, filename)
				VALUES		(?, 'config.inc.php')";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute(array($this->installation->getPackageID()));
		}
		
		// delete temporary sourceArchive
		@unlink($sourceFile);
		
		// update acp style file
		StyleUtil::updateStyleFile();
	}
 /**
  * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     // search sql files in package archive
     if (($fileIndex = $this->installation->getArchive()->getTar()->getIndexByFilename($this->instruction['value'])) === false) {
         throw new SystemException("Package icon '" . $this->instruction['value'] . "' not found.");
     }
     // get extension
     $extension = substr($this->instruction['value'], strrpos($this->instruction['value'], '.'));
     // extract image
     $this->installation->getArchive()->getTar()->extract($fileIndex, WCF_DIR . 'icon/packages/' . $this->installation->getPackage()->packageID . $extension);
     // update package
     $packageEditor = new PackageEditor($this->installation->getPackage());
     $packageEditor->update(array('packageIcon' => 'icon/packages/' . $packageEditor->packageID . $extension));
 }
 /**
  * Uninstalls current package.
  *
  * @param	array		$nodeData
  */
 protected function uninstallPackage(array $nodeData)
 {
     PackageEditor::deleteAll(array($this->queue->packageID));
     // remove localized package infos
     // todo: license/readme
     $sql = "DELETE FROM\twcf" . WCF_N . "_language_item\n\t\t\tWHERE\t\tlanguageItem IN (?, ?)";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array('wcf.acp.package.packageName.package' . $this->queue->packageID, 'wcf.acp.package.packageDescription.package' . $this->queue->packageID));
     // reset package cache
     CacheHandler::getInstance()->clearResource('packages');
     // rebuild package dependencies
     Package::rebuildParentPackageDependencies($this->queue->packageID);
 }
	/**
	 * Executes post-setup actions.
	 */
	public function completeSetup() {
		// mark queue as done
		$queueEditor = new PackageInstallationQueueEditor($this->queue);
		$queueEditor->update(array(
			'done' => 1
		));
		
		// remove node data
		$this->nodeBuilder->purgeNodes();
		
		// update package version
		if ($this->action == 'update') {
			$packageEditor = new PackageEditor($this->getPackage());
			$packageEditor->update(array(
				'updateDate' => TIME_NOW,
				'packageVersion' => $this->getArchive()->getPackageInfo('version')
			));
		}
		
		// clear language files once whole installation is completed
		LanguageEditor::deleteLanguageFiles();
		
		// reset all caches
		CacheHandler::getInstance()->flushAll();
	}
Exemple #5
0
 /**
  * Loads an application.
  * 
  * @param	\wcf\data\application\Application		$application
  * @param	boolean						$isDependentApplication
  * @return	\wcf\system\application\IApplication
  */
 protected function loadApplication(Application $application, $isDependentApplication = false)
 {
     $applicationObject = null;
     $package = PackageCache::getInstance()->getPackage($application->packageID);
     // package cache might be outdated
     if ($package === null) {
         $package = new Package($application->packageID);
         // package cache is outdated, discard cache
         if ($package->packageID) {
             PackageEditor::resetCache();
         } else {
             // package id is invalid
             throw new SystemException("application identified by package id '" . $application->packageID . "' is unknown");
         }
     }
     $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
     $packageDir = FileUtil::getRealPath(WCF_DIR . $package->packageDir);
     self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/';
     $className = $abbreviation . '\\system\\' . strtoupper($abbreviation) . 'Core';
     if (class_exists($className) && ClassUtil::isInstanceOf($className, 'wcf\\system\\application\\IApplication')) {
         // include config file
         $configPath = $packageDir . PackageInstallationDispatcher::CONFIG_FILE;
         if (file_exists($configPath)) {
             require_once $configPath;
         } else {
             throw new SystemException('Unable to load configuration for ' . $package->package);
         }
         // register template path if not within ACP
         if (!class_exists('wcf\\system\\WCFACP', false)) {
             // add template path and abbreviation
             $this->getTPL()->addApplication($abbreviation, $packageDir . 'templates/');
         }
         // init application and assign it as template variable
         self::$applicationObjects[$application->packageID] = call_user_func(array($className, 'getInstance'));
         $this->getTPL()->assign('__' . $abbreviation, self::$applicationObjects[$application->packageID]);
     } else {
         unset(self::$autoloadDirectories[$abbreviation]);
         throw new SystemException("Unable to run '" . $package->package . "', '" . $className . "' is missing or does not implement 'wcf\\system\\application\\IApplication'.");
     }
     // register template path in ACP
     if (class_exists('wcf\\system\\WCFACP', false)) {
         $this->getTPL()->addApplication($abbreviation, $packageDir . 'acp/templates/');
     } else {
         if (!$isDependentApplication) {
             // assign base tag
             $this->getTPL()->assign('baseHref', $application->getPageURL());
         }
     }
     // register application
     self::$applications[$abbreviation] = $application;
     return self::$applicationObjects[$application->packageID];
 }
 /**
  * Prompts for a text input for package directory (applies for applications only)
  * 
  * @return	\wcf\system\form\FormDocument
  */
 protected function promptPackageDir()
 {
     if (!PackageInstallationFormManager::findForm($this->queue, 'packageDir')) {
         $container = new GroupFormElementContainer();
         $packageDir = new TextInputFormElement($container);
         $packageDir->setName('packageDir');
         $packageDir->setLabel(WCF::getLanguage()->get('wcf.acp.package.packageDir.input'));
         $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(dirname(WCF_DIR)));
         // check if there is already an application
         $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\tWHERE\tpackageDir = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array('../'));
         $row = $statement->fetchArray();
         if ($row['count']) {
             // use abbreviation
             $defaultPath .= strtolower(Package::getAbbreviation($this->getPackage()->package)) . '/';
         }
         $packageDir->setValue($defaultPath);
         $container->appendChild($packageDir);
         $document = new FormDocument('packageDir');
         $document->appendContainer($container);
         PackageInstallationFormManager::registerForm($this->queue, $document);
         return $document;
     } else {
         $document = PackageInstallationFormManager::getForm($this->queue, 'packageDir');
         $document->handleRequest();
         $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(FileUtil::unifyDirSeparator($document->getValue('packageDir'))));
         if ($packageDir === '/') {
             $packageDir = '';
         }
         if ($packageDir !== null) {
             // validate package dir
             if (file_exists($packageDir . 'global.php')) {
                 $document->setError('packageDir', WCF::getLanguage()->get('wcf.acp.package.packageDir.notAvailable'));
                 return $document;
             }
             // set package dir
             $packageEditor = new PackageEditor($this->getPackage());
             $packageEditor->update(array('packageDir' => FileUtil::getRelativePath(WCF_DIR, $packageDir)));
             // determine domain path, in some environments (e.g. ISPConfig) the $_SERVER paths are
             // faked and differ from the real filesystem path
             if (PACKAGE_ID) {
                 $wcfDomainPath = ApplicationHandler::getInstance()->getWCF()->domainPath;
             } else {
                 $sql = "SELECT\tdomainPath\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_application\n\t\t\t\t\t\tWHERE\tpackageID = ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute(array(1));
                 $row = $statement->fetchArray();
                 $wcfDomainPath = $row['domainPath'];
             }
             $documentRoot = str_replace($wcfDomainPath, '', FileUtil::unifyDirSeparator(WCF_DIR));
             $domainPath = str_replace($documentRoot, '', $packageDir);
             // update application path
             $application = new Application($this->getPackage()->packageID);
             $applicationEditor = new ApplicationEditor($application);
             $applicationEditor->update(array('domainPath' => $domainPath, 'cookiePath' => $domainPath));
             // create directory and set permissions
             @mkdir($packageDir, 0777, true);
             FileUtil::makeWritable($packageDir);
         }
         return null;
     }
 }
	/**
	 * Uninstalls current package.
	 * 
	 * @param	array		$nodeData
	 */
	protected function uninstallPackage(array $nodeData) {
		PackageEditor::deleteAll(array($this->queue->packageID));
		
		// remove localized package infos
		// todo: license/readme
		$sql = "DELETE FROM	wcf".WCF_N."_language_item
			WHERE		languageItem IN (?, ?)";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute(array(
			'wcf.acp.package.packageName.package'.$this->queue->packageID,
			'wcf.acp.package.packageDescription.package'.$this->queue->packageID
		));
		
		// reset package cache
		PackageCacheBuilder::getInstance()->reset();
	}