*/ class UpdateServerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin { /** * tag name * * @var string */ public $tagName = 'updateserver'; /** * table name * * @var string */ public $tableName = 'package_update_server'; /** * update servers * * @var array */ protected $updateServers = array(); /** * ignores Package uninstallation */ public function hasUninstall() { return false; } /** * @see PackageInstallationPlugin::install() */ public function install() { parent::install(); if (!$xml = $this->getXML()) { return; } // read all update servers $sql = "SELECT server FROM wcf".WCF_N."_package_update_server"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $this->updateServers[] = $row['server']; } // create an array with the data blocks (import or delete) from the xml file. $permissionDataXML = $xml->getElementTree('data'); // loop through the array and install or uninstall update servers. foreach ($permissionDataXML['children'] as $key => $block) { if (count($block['children'])) { // handle the import instructions if ($block['name'] == 'import') { // loop through update servers and create or update them. foreach ($block['children'] as $updateServerData) { // extract permission properties. foreach ($updateServerData['children'] as $child) { if (!isset($child['cdata'])) continue; $updateServerData[$child['name']] = $child['cdata']; } // check required attributes if (!isset($updateServerData['serverurl'])) { throw new SystemException("Required 'serverURL' attribute for update servers is missing", 13023); } // check for update server if (in_array($updateServerData['serverurl'], $this->updateServers)) continue; // set default values $loginUsername = $loginPassword = ''; // get values $serverURL = $updateServerData['serverurl']; if (isset($updateServerData['loginUsername'])) $loginUsername = $updateServerData['loginUsername']; if (isset($updateServerData['loginPassword'])) $loginPassword = $updateServerData['loginPassword']; // insert items $sql = "INSERT INTO wcf".WCF_N."_package_update_server (server, htUsername, htPassword) VALUES ('".escapeString($serverURL)."', '".escapeString($loginUsername)."', '".escapeString($loginPassword)."')"; WCF::getDB()->sendQuery($sql); } } // handle the delete instructions. else if ($block['name'] == 'delete') { if ($this->installation->getAction() == 'update') { // loop through update servers and delete them. $serverURLs = array(); foreach ($block['children'] as $updateServerData) { // extract permission properties. foreach ($updateServerData['children'] as $child) { if (!isset($child['cdata'])) continue; $updateServerData[$child['name']] = $child['cdata']; } // check required attributes if (!isset($updateServerData['serverurl'])) { throw new SystemException("Required 'serverURL' attribute for update servers is missing", 13023); } // add to server urls $serverURLs[] = $updateServerData['serverurl']; } // delete update servers if (count($serverURLs)) { $sql = "DELETE FROM wcf".WCF_N."_package_update_server WHERE server IN ('".implode("','", array_map('escapeString', $serverURLs))."')"; WCF::getDB()->sendQuery($sql); } } } } } } } ?>