/**
	 * @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));
 }
	/**
	 * 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();
	}
 /**
  * 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;
     }
 }