示例#1
0
 /**
  * this function detects parameter sets that are no longer referred and
  * web services that are no longer used in this article
  *
  * @param string $articleId
  *
  * @return boolean true
  */
 public static function detectRemovedWebServiceUsages($articleId)
 {
     global $wgsmwRememberedWSUsages, $purgePage;
     $purgePage = false;
     $rememberedWSUsages = $wgsmwRememberedWSUsages;
     if ($rememberedWSUsages != null) {
         foreach ($rememberedWSUsages as $rememberedWSUsage) {
             WSStorage::getDatabase()->addWSArticle($rememberedWSUsage[0], $rememberedWSUsage[1], $articleId);
         }
     }
     $oldWSUsages = WSStorage::getDatabase()->getWSsUsedInArticle($articleId);
     foreach ($oldWSUsages as $oldWSUsage) {
         $remove = true;
         if ($rememberedWSUsages != null) {
             foreach ($rememberedWSUsages as $rememberedWSUsage) {
                 if ($rememberedWSUsage[0] == $oldWSUsage[0] && $rememberedWSUsage[1] == $oldWSUsage[1]) {
                     $remove = false;
                 }
             }
         }
         if ($remove) {
             WSStorage::getDatabase()->removeWSArticle($oldWSUsage[0], $oldWSUsage[1], $articleId);
             WebServiceCache::removeWSParameterPair($oldWSUsage[0], $oldWSUsage[1]);
             $parameterSetIds = WSStorage::getDatabase()->getUsedParameterSetIds($oldWSUsage[1]);
             if (sizeof($parameterSetIds) == 0) {
                 WSStorage::getDatabase()->removeParameterSet($oldWSUsage[1]);
             }
         }
     }
     $wgsmwRememberedWSUsages = array();
     //deal with triplifying
     global $wgsmwRememberedWSTriplifications;
     if (!is_array($wgsmwRememberedWSTriplifications)) {
         $wgsmwRememberedWSTriplifications = array();
     }
     foreach ($oldWSUsages as $oldWSUsage) {
         if (!array_key_exists($oldWSUsage[0], $wgsmwRememberedWSTriplifications)) {
             WSTriplifier::getInstance()->removeWSUsage($oldWSUsage[0], $articleId);
         }
     }
     $wgsmwRememberedWSTriplifications = array();
     //eof deal with triplification
     return true;
 }
 public static function articleDeleteHook(&$article, &$user, $reason)
 {
     if ($article->getTitle()->getNamespace() != SMW_NS_WEB_SERVICE) {
         return true;
     }
     $ws = WebService::newFromID($article->getID());
     if ($ws) {
         //triplification processing
         global $smwgDIIP;
         require_once $smwgDIIP . "/specials/WebServices/SMW_WSTriplifier.php";
         //deal with triplification
         $articles = WSStorage::getDatabase()->getWSArticles($article->getID(), new SMWRequestOptions());
         WSTriplifier::getInstance()->removeWS($article->getID(), $articles);
         WebServiceCache::removeWS($ws->getArticleID());
         $options = new SMWRequestOptions();
         $pageIds = WSStorage::getDatabase()->getWSArticles($ws->getArticleID(), $options);
         foreach ($pageIds as $articleId) {
             $usedWSs = WSStorage::getDatabase()->getWSsUsedInArticle($articleId);
             foreach ($usedWSs as $usedWS) {
                 if ($usedWS[0] == $ws->getArticleID()) {
                     WSStorage::getDatabase()->removeWSArticle($ws->getArticleID(), $usedWS[1], $articleId);
                     $parameterSetIds = WSStorage::getDatabase()->getUsedParameterSetIds($usedWS[1]);
                     if (sizeof($parameterSetIds) == 0) {
                         WSStorage::getDatabase()->removeParameterSet($usedWS[1]);
                     }
                 }
             }
         }
         $ws->removeFromDB();
     }
     self::$mNewWebService = null;
     self::$mOldWebservice = null;
     return true;
 }