/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); // get installation path of package $sql = "SELECT packageDir FROM wcf".WCF_N."_package WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID())); $packageDir = $statement->fetchArray(); $packageDir = $packageDir['packageDir']; // get relative path of script $path = FileUtil::getRealPath(WCF_DIR.$packageDir); // reset WCF cache CacheHandler::getInstance()->flushAll(); // run script $this->run($path.$this->instruction['value']); // delete script if (@unlink($path.$this->instruction['value'])) { // delete file log entry $sql = "DELETE FROM wcf".WCF_N."_package_installation_file_log WHERE packageID = ? AND filename = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( $this->installation->getPackageID(), $this->instruction['value'] )); } }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); // extract files.tar to temp folder $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'acptemplates_'); // create file handler $fileHandler = new ACPTemplatesFileHandler($this->installation); // extract content of files.tar $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$this->installation->getPackage()->packageDir)); try { $fileInstaller = $this->installation->extractFiles($packageDir.'acp/templates/', $sourceFile, $fileHandler); } catch (SystemException $e) { WCF::getTPL()->assign(array( 'exception' => $e )); WCF::getTPL()->display('packageInstallationFileInstallationFailed'); exit; } // delete temporary sourceArchive @unlink($sourceFile); }
/** * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); $abbreviation = 'wcf'; $path = ''; if (isset($this->instruction['attributes']['application'])) { $abbreviation = $this->instruction['attributes']['application']; } else { if ($this->installation->getPackage()->isApplication) { $path = FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir); } } if (empty($path)) { $dirConstant = strtoupper($abbreviation) . '_DIR'; if (!defined($dirConstant)) { throw new SystemException("Cannot execute script-PIP, abbreviation '" . $abbreviation . "' is unknown"); } $path = constant($dirConstant); } // reset WCF cache CacheHandler::getInstance()->flushAll(); // run script $this->run($path . $this->instruction['value']); // delete script if (@unlink($path . $this->instruction['value'])) { // delete file log entry $sql = "DELETE FROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\tWHERE\t\tpackageID = ?\n\t\t\t\t\t\tAND filename = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID(), $this->instruction['value'])); } }
/** * @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(); // extract files.tar to temp folder $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'templates_'); // create file handler $fileHandler = new TemplatesFileHandler($this->installation); // extract content of files.tar $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir)); $fileInstaller = $this->installation->extractFiles($packageDir . 'templates/', $sourceFile, $fileHandler); // delete temporary sourceArchive @unlink($sourceFile); }
/** * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { AbstractPackageInstallationPlugin::install(); $xml = $this->getXML($this->instruction['value']); $xpath = $xml->xpath(); if ($this->installation->getAction() == 'update') { // handle delete first $this->deleteItems($xpath); } // import or update categories $this->importCategories($xpath); // import or update options $this->importOptions($xpath); }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); // extract style tar $filename = $this->installation->getArchive()->extractTar($this->instructions['value'], 'style_'); // import style $style = StyleEditor::import($filename, $this->installation->getPackageID()); // set style as default if (isset($this->instruction['attributes']['default'])) { $style->setAsDefault(); } // remove tmp file @unlink($filename); }
/** * @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)); }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); // get xml $xml = $this->getXML($this->instruction['value']); $xpath = $xml->xpath(); // handle delete first if ($this->installation->getAction() == 'update') { $this->deleteItems($xpath); } // handle import $this->importItems($xpath); // execute cleanup after successfull import/delete/update $this->cleanup(); }
/** * @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(); // replace app1_ with app{WCF_N}_ in the table names for // all applications $packageList = new PackageList(); $packageList->getConditionBuilder()->add('package.isApplication = ?', array(1)); $packageList->readObjects(); foreach ($packageList as $package) { $abbreviation = Package::getAbbreviation($package->package); $queries = str_replace($abbreviation . '1_', $abbreviation . WCF_N . '_', $queries); } // check queries $parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction()); $conflicts = $parser->test(); if (!empty($conflicts) && (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE']))) { $unknownCreateTable = isset($conflicts['CREATE TABLE']) ? $conflicts['CREATE TABLE'] : array(); $unknownDropTable = isset($conflicts['DROP TABLE']) ? $conflicts['DROP TABLE'] : array(); $errorMessage = "Can't"; if (!empty($unknownDropTable)) { $errorMessage .= " drop unknown table"; if (count($unknownDropTable) > 1) { $errorMessage .= "s"; } $errorMessage .= " '" . implode("', '", $unknownDropTable) . "'"; } if (!empty($unknownCreateTable)) { if (!empty($unknownDropTable)) { $errorMessage .= " and can't"; } $errorMessage .= " overwrite unknown table"; if (count($unknownCreateTable) > 1) { $errorMessage .= "s"; } $errorMessage .= " '" . implode("', '", $unknownCreateTable) . "'"; } throw new SystemException($errorMessage); } // execute queries $parser->execute(); // log changes $parser->log(); } }
/** * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); $abbreviation = 'wcf'; if (isset($this->instruction['attributes']['application'])) { $abbreviation = $this->instruction['attributes']['application']; } else { if ($this->installation->getPackage()->isApplication) { $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package); } } // absolute path to package dir $packageDir = Application::getDirectory($abbreviation); // extract files.tar to temp folder $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'templates_'); // create file handler $fileHandler = new TemplatesFileHandler($this->installation, $abbreviation); $this->installation->extractFiles($packageDir . 'templates/', $sourceFile, $fileHandler); // delete temporary sourceArchive @unlink($sourceFile); }
/** * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); $abbreviation = 'wcf'; if (isset($this->instruction['attributes']['application'])) { $abbreviation = $this->instruction['attributes']['application']; } else { if ($this->installation->getPackage()->isApplication) { $abbreviation = Package::getAbbreviation($this->installation->getPackage()->package); } } // absolute path to package dir $packageDir = Application::getDirectory($abbreviation); // extract files.tar to temp folder $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'files_'); // create file handler $fileHandler = new FilesFileHandler($this->installation, $abbreviation); // 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' && $abbreviation != 'wcf') { // touch file $fileInstaller->touchFile(PackageInstallationDispatcher::CONFIG_FILE); // create file Package::writeConfigFile($this->installation->getPackageID()); // log file $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\t\t\t(packageID, filename, application)\n\t\t\t\tVALUES\t\t(?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID(), 'config.inc.php', Package::getAbbreviation($this->installation->getPackage()->package))); // load application WCF::loadRuntimeApplication($this->installation->getPackageID()); } // delete temporary sourceArchive @unlink($sourceFile); // update acp style file StyleUtil::updateStyleFile(); }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { AbstractPackageInstallationPlugin::install(); // get language files $languageFiles = array(); $multipleFiles = false; $filename = $this->instruction['value']; if (strpos($filename, '*') !== false) { // wildcard syntax; import multiple files $multipleFiles = true; $files = $this->installation->getArchive()->getTar()->getContentList(); $pattern = str_replace("\\*", ".*", preg_quote($filename)); foreach ($files as $file) { if (preg_match('!' . $pattern . '!i', $file['filename'])) { if (preg_match('~([a-z-]+)\\.xml$~i', $file['filename'], $match)) { $languageFiles[$match[1]] = $file['filename']; } else { throw new SystemException("Can not determine language code of language file '" . $file['filename'] . "'"); } } } } else { if (!empty($this->instruction['attributes']['languagecode'])) { $languageCode = $this->instruction['attributes']['languagecode']; } else { if (!empty($this->instruction['attributes']['language'])) { $languageCode = $this->instruction['attributes']['language']; } else { if (preg_match('~([a-z-]+)\\.xml$~i', $filename, $match)) { $languageCode = $match[1]; } else { throw new SystemException("Can not determine language code of language file '" . $filename . "'"); } } } $languageFiles[$languageCode] = $filename; } // get installed languages $installedLanguages = array(); $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_language\n\t\t\tORDER BY\tisDefault DESC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); while ($row = $statement->fetchArray()) { $installedLanguages[] = $row; } // install language $addedLanguageIDArray = array(); foreach ($installedLanguages as $installedLanguage) { $languageFile = null; if (isset($languageFiles[$installedLanguage['languageCode']])) { $languageFile = $languageFiles[$installedLanguage['languageCode']]; } else { if ($multipleFiles) { // use default language if (isset($languageFiles[$installedLanguages[0]['languageCode']])) { $languageFile = $languageFiles[$installedLanguages[0]['languageCode']]; } else { if (isset($languageFiles['en'])) { foreach ($installedLanguages as $installedLanguage2) { if ($installedLanguage2['languageCode'] == 'en') { $languageFile = $languageFiles['en']; break; } } } } // use any installed language if ($languageFile === null) { foreach ($installedLanguages as $installedLanguage2) { if (isset($languageFiles[$installedLanguage2['languageCode']])) { $languageFile = $languageFiles[$installedLanguage2['languageCode']]; break; } } } // use first delivered language if ($languageFile === null) { foreach ($languageFiles as $languageFile) { break; } } } } // save language if ($languageFile !== null) { if ($xml = $this->readLanguage($languageFile)) { // get language object $language = LanguageFactory::getInstance()->getLanguageByCode($installedLanguage['languageCode']); $languageEditor = new LanguageEditor($language); // import xml // don't update language files if package is an application $languageEditor->updateFromXML($xml, $this->installation->getPackageID(), !$this->installation->getPackage()->isApplication); // add language to this package $addedLanguageIDArray[] = $language->languageID; } } } // save package to language if (count($addedLanguageIDArray)) { $condition = ''; $statementParameters = array($this->installation->getPackageID()); foreach ($addedLanguageIDArray as $languageID) { if (!empty($condition)) { $condition .= ','; } $condition .= '?'; $statementParameters[] = $languageID; } $statementParameters[] = $this->installation->getPackageID(); $sql = "INSERT INTO\twcf" . WCF_N . "_language_to_package\n\t\t\t\t\t\t(languageID, packageID)\n\t\t\t\tSELECT\t\tlanguageID, ?\n\t\t\t\tFROM\t\twcf" . WCF_N . "_language\n\t\t\t\tWHERE\t\tlanguageID IN (" . $condition . ")\n\t\t\t\t\t\tAND languageID NOT IN (\n\t\t\t\t\t\t\tSELECT\tlanguageID\n\t\t\t\t\t\t\tFROM\twcf" . WCF_N . "_language_to_package\n\t\t\t\t\t\t\tWHERE\tpackageID = ?\n\t\t\t\t\t\t)"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($statementParameters); } }
/** * @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(); } }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { AbstractPackageInstallationPlugin::install(); // get language files $languageFiles = array(); $multipleFiles = false; $filename = $this->instruction['value']; if (strpos($filename, '*') !== false) { // wildcard syntax; import multiple files $multipleFiles = true; $files = $this->installation->getArchive()->getTar()->getContentList(); $pattern = str_replace("\*", ".*", preg_quote($filename)); foreach ($files as $file) { if (preg_match('!'.$pattern.'!i', $file['filename'])) { if (preg_match('~([a-z-]+)\.xml$~i', $file['filename'], $match)) { $languageFiles[$match[1]] = $file['filename']; } else { throw new SystemException("Can not determine language code of language file '".$file['filename']."'"); } } } } else { if (!empty($this->instruction['attributes']['languagecode'])) { $languageCode = $this->instruction['attributes']['languagecode']; } else if (!empty($this->instruction['attributes']['language'])) { $languageCode = $this->instruction['attributes']['language']; } else if (preg_match('~([a-z-]+)\.xml$~i', $filename, $match)) { $languageCode = $match[1]; } else { throw new SystemException("Can not determine language code of language file '".$filename."'"); } $languageFiles[$languageCode] = $filename; } // get installed languages $installedLanguages = array(); $sql = "SELECT * FROM wcf".WCF_N."_language ORDER BY isDefault DESC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); while ($row = $statement->fetchArray()) { $installedLanguages[] = $row; } // install language foreach ($installedLanguages as $installedLanguage) { $languageFile = null; if (isset($languageFiles[$installedLanguage['languageCode']])) { $languageFile = $languageFiles[$installedLanguage['languageCode']]; } else if ($multipleFiles) { // use default language if (isset($languageFiles[$installedLanguages[0]['languageCode']])) { $languageFile = $languageFiles[$installedLanguages[0]['languageCode']]; } // use english (if installed) else if (isset($languageFiles['en'])) { foreach ($installedLanguages as $installedLanguage2) { if ($installedLanguage2['languageCode'] == 'en') { $languageFile = $languageFiles['en']; break; } } } // use any installed language if ($languageFile === null) { foreach ($installedLanguages as $installedLanguage2) { if (isset($languageFiles[$installedLanguage2['languageCode']])) { $languageFile = $languageFiles[$installedLanguage2['languageCode']]; break; } } } // use first delivered language if ($languageFile === null) { foreach ($languageFiles as $languageFile) break; } } // save language if ($languageFile !== null) { if ($xml = $this->readLanguage($languageFile)) { // get language object $language = LanguageFactory::getInstance()->getLanguageByCode($installedLanguage['languageCode']); $languageEditor = new LanguageEditor($language); // import xml // don't update language files if package is an application $languageEditor->updateFromXML($xml, $this->installation->getPackageID(), !$this->installation->getPackage()->isApplication); } } } }