Esempio n. 1
0
 /**
  * Get HTML email message and list of email recipients from given email
  * info.
  *
  * @param ORMRow $emailInfo
  * @return array With 'message' and 'recipients' items.
  */
 protected function prepareTemplate($emailInfo)
 {
     $template = $emailInfo->getField('template');
     $params = $emailInfo->getField('params');
     $fauxreq = new FauxRequest(array('action' => 'parse', 'text' => $this->getTemplate($template, $params), 'contentmodel' => 'wikitext'));
     $api = new ApiMain($fauxreq);
     $api->execute();
     $data = $api->getResultData();
     $message = $data['parse']['text']['*'];
     $recipients = array();
     foreach ($params['To'] as $to) {
         $recipients[] = new MailAddress($to);
     }
     return array('message' => $message, 'recipients' => $recipients);
 }
Esempio n. 2
0
 /**
  * Returns a new Site object constructed from the provided ORMRow.
  *
  * @since 1.21
  *
  * @param ORMRow $siteRow
  *
  * @return Site
  */
 protected function siteFromRow(ORMRow $siteRow)
 {
     wfProfileIn(__METHOD__);
     $site = Site::newForType($siteRow->getField('type', Site::TYPE_UNKNOWN));
     $site->setGlobalId($siteRow->getField('global_key'));
     $site->setInternalId($siteRow->getField('id'));
     if ($siteRow->hasField('forward')) {
         $site->setForward($siteRow->getField('forward'));
     }
     if ($siteRow->hasField('group')) {
         $site->setGroup($siteRow->getField('group'));
     }
     if ($siteRow->hasField('language')) {
         $site->setLanguageCode($siteRow->getField('language') === '' ? null : $siteRow->getField('language'));
     }
     if ($siteRow->hasField('source')) {
         $site->setSource($siteRow->getField('source'));
     }
     if ($siteRow->hasField('data')) {
         $site->setExtraData($siteRow->getField('data'));
     }
     if ($siteRow->hasField('config')) {
         $site->setExtraConfig($siteRow->getField('config'));
     }
     wfProfileOut(__METHOD__);
     return $site;
 }
 /**
  * @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. 4
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;
 }