/** 
  * @see PackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     // extract the file containing the patches (the 'diff') directly to a string ...
     $patchFileName = $this->installation->getXMLTag($this->tagName);
     // get the attribute containing the fuzz factor value.
     $fuzzFactor = 2;
     $instructions = $this->installation->getArchive()->getInstructions('install');
     foreach ($instructions as $key => $instruction) {
         if ($key == $this->tagName && isset($instruction['fuzzfactor']) && $instruction['fuzzfactor']) {
             $fuzzFactor = $instruction['fuzzfactor'];
             break;
         }
     }
     $patchFileString = $this->installation->getArchive()->getTar()->extractToString($patchFileName['cdata']);
     // ... and pass that string to a new object instance of TemplatePatch.class.
     require_once WCF_DIR . 'lib/system/template/patch/TemplatePatch.class.php';
     try {
         $patchObject = new TemplatePatch($this->installation->getPackageID(), $patchFileString, false, false, 0, $this->type, $fuzzFactor);
     } catch (TemplatePatchException $e) {
         // be a bit more friendly to the user.
         WCF::getTPL()->assign(array('errorCode' => $e->getCode(), 'errorMessage' => $e->getMessage(), 'affectedTemplateName' => $e->getTemplateName()));
         WCF::getTPL()->display('packageInstallationPatchFailed');
         exit;
     }
 }
 /** 
  * @see PackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     require_once WCF_DIR . 'lib/data/style/StyleEditor.class.php';
     $instructions = $this->installation->getInstructions();
     $styles = $instructions['style'];
     if (count($styles) && isset($styles['cdata'])) {
         $styles = array($styles);
     }
     // Install each <style>-tag from package.xml
     foreach ($styles as $styleData) {
         // extract style tar from package archive
         // No <style>-tag in the instructions in package.xml
         if (!isset($styleData['cdata']) || !$styleData['cdata']) {
             return false;
         }
         // extract style tar
         $filename = $this->installation->getArchive()->extractTar($styleData['cdata'], 'style_');
         // import style
         $style = StyleEditor::import($filename, $this->installation->getPackageID());
         // set wcf basic style as default
         if (isset($styleData['default'])) {
             $style->setAsDefault();
         }
         // delete tmp file
         @unlink($filename);
     }
 }
 /**
  * Uninstalls the templates of this package.
  */
 public function uninstall()
 {
     // create templates list
     $templates = array();
     // get templates from log
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_template\n\t\t\tWHERE \tpackageID = " . $this->installation->getPackageID();
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $files[] = 'templates/' . $row['templateName'] . '.tpl';
     }
     if (count($files) > 0) {
         // delete template files
         $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->getDir()));
         $deleteEmptyDirectories = $this->installation->getPackage()->isStandalone();
         $this->installation->deleteFiles($packageDir, $files, false, $deleteEmptyDirectories);
         // delete log entries
         parent::uninstall();
     }
 }
 /** 
  * Runs a script.
  */
 public function install()
 {
     parent::install();
     // get installation path of package
     $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackageID = " . $this->installation->getPackageID();
     $packageDir = WCF::getDB()->getFirstRow($sql);
     $packageDir = $packageDir['packageDir'];
     // get relative path of script
     $scriptTag = $this->installation->getXMLTag('script');
     $path = FileUtil::getRealPath(WCF_DIR . $packageDir);
     // run script
     $this->run($path . $scriptTag['cdata']);
     // delete script
     if (@unlink($path . $scriptTag['cdata'])) {
         // delete file log entry
         $sql = "DELETE FROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\tWHERE\t\tpackageID = " . $this->installation->getPackageID() . "\n\t\t\t\t\t\tAND filename = '" . escapeString($scriptTag['cdata']) . "'";
         WCF::getDB()->sendQuery($sql);
     }
 }
 /**
  * Uninstalls the files of this package.
  */
 public function uninstall()
 {
     // get absolute package dir
     $packageDir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(realpath(WCF_DIR . $this->installation->getPackage()->getDir())));
     // create file list
     $files = array();
     // get files from log
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\tWHERE \tpackageID = " . $this->installation->getPackageID();
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $files[] = $row['filename'];
     }
     if (count($files) > 0) {
         // delete files
         $this->installation->deleteFiles($packageDir, $files);
         // delete log entries
         parent::uninstall();
     }
 }
 /** 
  * Deletes the sql tables or columns which where installed by the package.
  */
 public function uninstall()
 {
     // get logged sql tables/columns
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_sql_log\n\t\t\tWHERE\tpackageID = " . $this->installation->getPackageID();
     $result = WCF::getDB()->sendQuery($sql);
     $entries = array();
     while ($row = WCF::getDB()->fetchArray($result)) {
         $entries[] = $row;
     }
     // get all tablenames from database
     $existingTableNames = WCF::getDB()->getTablenames();
     // delete or alter tables
     foreach ($entries as $entry) {
         // don't alter table if it should be dropped
         if (!empty($entry['sqlColumn']) || !empty($entry['sqlIndex'])) {
             $isDropped = false;
             foreach ($entries as $entry_) {
                 if ($entry['sqlTable'] == $entry_['sqlTable'] && empty($entry_['sqlColumn']) && empty($entry_['sqlIndex'])) {
                     $isDropped = true;
                 }
             }
             if ($isDropped) {
                 continue;
             }
         }
         // drop table
         if (!empty($entry['sqlTable']) && empty($entry['sqlColumn']) && empty($entry['sqlIndex'])) {
             WCF::getDB()->sendQuery("DROP TABLE IF EXISTS " . $entry['sqlTable']);
         } elseif (in_array($entry['sqlTable'], $existingTableNames) && !empty($entry['sqlColumn']) && empty($entry['sqlIndex'])) {
             WCF::getDB()->sendQuery("ALTER TABLE \t`" . $entry['sqlTable'] . "` \n\t\t\t\t\t\t\t DROP COLUMN\t`" . $entry['sqlColumn']) . "`";
         } elseif (in_array($entry['sqlTable'], $existingTableNames) && empty($entry['sqlColumn']) && !empty($entry['sqlIndex'])) {
             WCF::getDB()->sendQuery("ALTER TABLE \t`" . $entry['sqlTable'] . "` \n\t\t\t\t\t\t\t DROP INDEX\t`" . $entry['sqlIndex']) . "`";
         }
     }
     // delete from log table
     parent::uninstall();
 }