/**
  * @see SiteStore::saveSites
  *
  * @since 1.21
  *
  * @param Site[] $sites
  *
  * @return boolean Success indicator
  */
 public function saveSites(array $sites)
 {
     wfProfileIn(__METHOD__);
     if (empty($sites)) {
         wfProfileOut(__METHOD__);
         return true;
     }
     $dbw = $this->sitesTable->getWriteDbConnection();
     $trx = $dbw->trxLevel();
     if ($trx == 0) {
         $dbw->begin(__METHOD__);
     }
     $success = true;
     $internalIds = array();
     $localIds = array();
     foreach ($sites as $site) {
         $fields = array('global_key' => $site->getGlobalId(), 'type' => $site->getType(), 'group' => $site->getGroup(), 'source' => $site->getSource(), 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(), 'protocol' => $site->getProtocol(), 'domain' => strrev($site->getDomain()) . '.', 'data' => $site->getExtraData(), 'forward' => $site->shouldForward(), 'config' => $site->getExtraConfig());
         if ($site->getInternalId() !== null) {
             $fields['id'] = $site->getInternalId();
             $internalIds[] = $site->getInternalId();
         }
         $siteRow = new ORMRow($this->sitesTable, $fields);
         $success = $siteRow->save(__METHOD__) && $success;
         foreach ($site->getLocalIds() as $idType => $ids) {
             foreach ($ids as $id) {
                 $localIds[] = array($siteRow->getId(), $idType, $id);
             }
         }
     }
     if ($internalIds !== array()) {
         $dbw->delete('site_identifiers', array('si_site' => $internalIds), __METHOD__);
     }
     foreach ($localIds as $localId) {
         $dbw->insert('site_identifiers', array('si_site' => $localId[0], 'si_type' => $localId[1], 'si_key' => $localId[2]), __METHOD__);
     }
     if ($trx == 0) {
         $dbw->commit(__METHOD__);
     }
     // purge cache
     $this->reset();
     wfProfileOut(__METHOD__);
     return $success;
 }
Esempio n. 2
0
 /**
  * @see ORMRow::save
  * @see Site::save
  *
  * @since 1.21
  *
  * @param string|null $functionName
  *
  * @return boolean Success indicator
  */
 public function save($functionName = null)
 {
     $dbw = wfGetDB(DB_MASTER);
     $trx = $dbw->trxLevel();
     if ($trx == 0) {
         $dbw->begin(__METHOD__);
     }
     $this->setField('protocol', $this->getProtocol());
     $this->setField('domain', strrev($this->getDomain()) . '.');
     $existedAlready = $this->hasIdField();
     $success = parent::save($functionName);
     if ($success && $existedAlready) {
         $dbw->delete('site_identifiers', array('si_site' => $this->getId()), __METHOD__);
     }
     if ($success && $this->localIds !== false) {
         foreach ($this->localIds as $type => $ids) {
             foreach ($ids as $id) {
                 $dbw->insert('site_identifiers', array('si_site' => $this->getId(), 'si_type' => $type, 'si_key' => $id), __METHOD__);
             }
         }
     }
     if ($trx == 0) {
         $dbw->commit(__METHOD__);
     }
     return $success;
 }