From: Marcel Werk Date: Tue, 19 Jul 2011 16:41:36 +0000 (+0200) Subject: sql pip renamed X-Git-Tag: 2.0.0_Beta_1~1995 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3569375e359b31fc3b78647cbb09f077bb324b1b;p=GitHub%2FWoltLab%2FWCF.git sql pip renamed --- diff --git a/wcfsetup/install/files/lib/system/package/plugin/SqlPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/SqlPackageInstallationPlugin.class.php deleted file mode 100644 index ab9f048571..0000000000 --- a/wcfsetup/install/files/lib/system/package/plugin/SqlPackageInstallationPlugin.class.php +++ /dev/null @@ -1,143 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.package.plugin - * @category Community Framework - */ -class SqlPackageInstallationPlugin extends AbstractPackageInstallationPlugin { - /** - * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName - */ - public $tableName = 'package_installation_sql_log'; - - /** - * @see wcf\system\package\plugin\PackageInstallationPlugin::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->standalone == 1) { - // package is standalone - $packageAbbr = $package->getAbbreviation(); - $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, $package, $this->installation->getAction()); - $conflicts = $parser->test(); - if (count($conflicts)) { - // 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(); - } - } - - /** - * Deletes the sql tables or columns which where installed by the package. - */ - public function uninstall() { - // get logged sql tables/columns - $sql = "SELECT * - FROM wcf".WCF_N."_package_installation_sql_log - WHERE packageID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($this->installation->getPackageID())); - $entries = array(); - while ($row = $statement->fetchArray()) { - $entries[] = $row; - } - - // get all tablenames from database - $existingTableNames = WCF::getDB()->getEditor()->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 $entry2) { - if ($entry['sqlTable'] == $entry2['sqlTable'] && empty($entry2['sqlColumn']) && empty($entry2['sqlIndex'])) { - $isDropped = true; - } - } - if ($isDropped) continue; - } - // drop table - if (!empty($entry['sqlTable']) && empty($entry['sqlColumn']) && empty($entry['sqlIndex'])) { - WCF::getDB()->getEditor()->dropTable($entry['sqlTable']); - } - // drop column - else if (in_array($entry['sqlTable'], $existingTableNames) && !empty($entry['sqlColumn'])) { - WCF::getDB()->getEditor()->dropColumn($entry['sqlTable'], $entry['sqlColumn']); - } - // drop index - else if (in_array($entry['sqlTable'], $existingTableNames) && !empty($entry['sqlIndex'])) { - WCF::getDB()->getEditor()->dropIndex($entry['sqlTable'], $entry['sqlIndex']); - } - } - // delete from log table - parent::uninstall(); - } - - /** - * Extracts and returns the sql file. - * If the specified sql file was not found, an error message is thrown. - * - * @param string $filename - * @return string - */ - protected function getSQL($filename) { - // search sql files in package archive - if (($fileindex = $this->installation->getArchive()->getTar()->getIndexByFilename($filename)) === false) { - throw new SystemException("SQL file '".$filename."' not found.", 13016); - } - - // extract sql file to string - return $this->installation->getArchive()->getTar()->extractToString($fileindex); - } -}