/** * Installs scm. * * @see AbstractXMLPackageInstallationPlugin::install() */ public function install() { parent::install(); if (!($xml = $this->getXML())) { return; } $scmXML = $xml->getElementTree('data'); foreach ($scmXML['children'] as $key => $block) { if (!empty($block['children'])) { switch ($block['name']) { // install (or update existing) scm case 'import': foreach ($block['children'] as $scm) { foreach ($scm['children'] as $child) { // continue with next children if current tree is empty if (!isset($child['cdata'])) { continue; } $scm[$child['name']] = $child['cdata']; } // break operation if we encounter missing attribute if (!isset($scm['attrs']['name'])) { throw new SystemException('Required "name" attribute for scm item tag is missing.'); } $scmName = $scm['attrs']['name']; // insert into db $sql = "INSERT INTO\twcf" . WCF_N . "_" . $this->tableName . "\r\n\t\t\t\t\t\t\t\t\t \t(packageID, scm)\r\n\t\t\t\t\t\t\t\tVALUES\t\t(" . $this->installation->getPackageID() . ", '" . strtolower($scmName) . "')\r\n\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE scm = VALUES(scm)"; WCF::getDB()->sendQuery($sql); // clear cache SCMHelper::clearCache(); } break; // delete scm // delete scm case 'delete': if ($package->getAction() == 'update') { $itemNames = ''; foreach ($block['children'] as $scm) { if (!isset($scm['attrs']['name'])) { throw new SystemException('Required "name" attribute for scm tag is missing.'); } if (!empty($itemNames)) { $itemNames .= ','; } $itemNames .= "'" . escapeString($scm['attrs']['name']) . "'"; } if (!empty($itemNames)) { $sql = "DELETE FROM\twcf" . WCF_N . "_" . $this->tableName . "\r\n\t\t\t\t\t\t\t \t\tWHERE\t\tscm IN (" . $itemNames . ")\r\n\t\t\t\t\t\t\t\t\t\t&&\tpackageID = " . $this->installation->getPackageID(); WCF::getDB()->sendQuery($sql); // clear cache SCMHelper::clearCache(); } } break; } } } }
/** * Deletes cache */ public static function clearCache() { if (empty(self::$data)) { self::registerCache(); } WCF::getCache()->clearResource('scm'); WCF::getCache()->clear(WCF_DIR . 'cache/', 'cache.scm.php'); self::$data = array(); }
/** * Validates a given SCM, if it is not available or unknown will return 'none' instead * * @param string $scm Source Code Management * @return string Valid SCM */ public static function validateSCM($scm) { return SCMHelper::getSCM($scm) ? SCMHelper::getSCM($scm) : 'none'; }
/** * @see Page::readData() */ public function readData() { parent::readData(); $this->availableSCM = SCMHelper::getSCM(); }