/**
  * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     // extract sql file from archive
     if ($queries = $this->getSQL($this->instruction['value'])) {
         $package = $this->installation->getPackage();
         if ($package->parentPackageID) {
             // package is a plugin; get parent package
             $package = $package->getParentPackage();
         }
         if ($package->isApplication == 1) {
             // package is application
             $packageAbbr = Package::getAbbreviation($package->package);
             $tablePrefix = WCF_N . '_' . $package->instanceNo . '_';
             // Replace the variable xyz1_1 with $tablePrefix in the table names.
             $queries = StringUtil::replace($packageAbbr . '1_1_', $packageAbbr . $tablePrefix, $queries);
         }
         // replace wcf1_  with the actual WCF_N value
         $queries = str_replace("wcf1_", "wcf" . WCF_N . "_", $queries);
         // check queries
         $parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction());
         $conflicts = $parser->test();
         if (!empty($conflicts)) {
             if (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE'])) {
                 if (!PackageInstallationFormManager::findForm($this->installation->queue, 'overwriteDatabaseTables')) {
                     $container = new GroupFormElementContainer();
                     if (isset($conflicts['CREATE TABLE'])) {
                         $text = implode('<br />', $conflicts['CREATE TABLE']);
                         $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable');
                         $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable.description');
                         $element = new LabelFormElement($container);
                         $element->setLabel($label);
                         $element->setText($text);
                         $element->setDescription($description);
                         $container->appendChild($element);
                     }
                     if (isset($conflicts['DROP TABLE'])) {
                         $text = implode('<br />', $conflicts['DROP TABLE']);
                         $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable');
                         $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable.description');
                         $element = new LabelFormElement($container);
                         $element->setLabel($label);
                         $element->setText($text);
                         $element->setDescription($description);
                         $container->appendChild($element);
                     }
                     $document = new FormDocument('overwriteDatabaseTables');
                     $document->appendContainer($container);
                     PackageInstallationFormManager::registerForm($this->installation->queue, $document);
                     return $document;
                 } else {
                     /*
                      * At this point the user decided to continue the installation (he would called the rollback
                      * otherwise), thus we do not care about the form anymore
                      */
                 }
             }
             // ask user here
             // search default value in session
             if (!WCF::getSession()->getVar('overrideAndDontAskAgain')) {
                 // show page
                 if (!empty($_POST['override']) || !empty($_POST['overrideAndDontAskAgain'])) {
                     if (!empty($_POST['overrideAndDontAskAgain'])) {
                         WCF::getSession()->register('overrideAndDontAskAgain', true);
                         WCF::getSession()->update();
                     }
                 } else {
                     WCF::getTPL()->assign('conflicts', $conflicts);
                     WCF::getTPL()->display('packageInstallationCheckOverrideTables');
                     exit;
                 }
             }
         }
         // execute queries
         $parser->execute();
         // log changes
         $parser->log();
     }
 }
	/**
	 * 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'));
			
			$path = RouteHandler::getPath(array('wcf', 'acp'));
			$defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($_SERVER['DOCUMENT_ROOT'] . $path));
			$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 = $document->getValue('packageDir');
			
			if ($packageDir !== null) {
				// validate package dir
				if (file_exists(FileUtil::addTrailingSlash($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)
				));
				
				// parse domain path
				$domainPath = FileUtil::getRelativePath(FileUtil::unifyDirSeperator($_SERVER['DOCUMENT_ROOT']), FileUtil::unifyDirSeperator($packageDir));
				
				// work-around for applications installed in document root
				if ($domainPath == './') {
					$domainPath = '';
				}
				
				$domainPath = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash($domainPath));
				
				// 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);
				@chmod($packageDir, 0777);
			}
			
			return null;
		}
	}
 /**
  * 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;
     }
 }