/**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     require_once dirname(__FILE__) . '/../../../config/ProjectConfiguration.class.php';
     $configuration = ProjectConfiguration::getApplicationConfiguration('public', 'prod', true);
     sfContext::createInstance($configuration);
     $liveLang = $arguments['live_lang'];
     $langToDeploy = $arguments['lang_to_deploy'];
     $liveLangs = SfConfig::get('app_site_langs');
     $langsUnderDev = SfConfig::get('app_site_langsUnderDev');
     if (in_array($liveLang, $liveLangs) === false) {
         die("The live lang doesn't seem to be live!");
     }
     if (in_array($langToDeploy, $langsUnderDev) === false) {
         die("You can deploy only a language under development");
     }
     $c = new Criteria();
     $c->add(PcTranslationPeer::LANGUAGE_ID, $langToDeploy);
     $translationsToDeploy = PcTranslationPeer::doSelect($c);
     $i = 0;
     foreach ($translationsToDeploy as $translationToDeploy) {
         $this->log("Deploying the string " . $translationToDeploy->getStringId() . " from {$langToDeploy} to {$liveLang}");
         $liveTranslation = PcTranslationPeer::retrieveByPK($liveLang, $translationToDeploy->getStringId());
         $liveTranslation->setString($translationToDeploy->getString())->save();
         $translationToDeploy->delete();
         $i++;
     }
     $this->log("All done. {$i} strings deployed.");
 }
 public function savePcTranslationList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['pc_translation_list'])) {
         // somebody has unset this widget
         return;
     }
     if (null === $con) {
         $con = $this->getConnection();
     }
     $c = new Criteria();
     $c->add(PcTranslationPeer::STRING_ID, $this->object->getPrimaryKey());
     PcTranslationPeer::doDelete($c, $con);
     $values = $this->getValue('pc_translation_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new PcTranslation();
             $obj->setStringId($this->object->getPrimaryKey());
             $obj->setLanguageId($value);
             $obj->save();
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @param string $languageId - 2-char string
  * @return PcString|null
  */
 public function getTranslation($languageId)
 {
     $c = new Criteria();
     $c->add(PcTranslationPeer::STRING_ID, $this->getId());
     $c->add(PcTranslationPeer::LANGUAGE_ID, $languageId);
     return PcTranslationPeer::doSelectOne($c);
 }
 function __($stringId)
 {
     if (!defined('PLANCAKE_PUBLIC_RELEASE')) {
         $lang = PcLanguagePeer::getUserPreferredLanguage()->getId();
         $key = '';
         if ($cache = PcCache::getInstance()) {
             $key = PcCache::generateKeyForTranslation($lang, $stringId);
             if ($cache->has($key)) {
                 return $cache->get($key);
             }
         }
         $translation = PcTranslationPeer::retrieveByPK($lang, $stringId);
         if (!is_object($translation) || !strlen(trim($translation->getString())) > 0) {
             $translation = PcTranslationPeer::retrieveByPK(SfConfig::get('app_site_defaultLang'), $stringId);
         }
         if (!$translation) {
             throw new Exception("Couldn't find the string {$stringId} for the language {$lang}");
         }
         $ret = $translation->getString();
         if ($cache) {
             $cache->set($key, $ret);
         }
     } else {
         global $pc_lang;
         if (!array_key_exists($stringId, $pc_lang)) {
             throw new Exception("Couldn't find the string {$stringId}");
         }
         $ret = $pc_lang[$stringId];
     }
     return $ret;
 }
Exemplo n.º 5
0
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = PcStringPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related PcTranslation objects
         $criteria = new Criteria(PcTranslationPeer::DATABASE_NAME);
         $criteria->add(PcTranslationPeer::STRING_ID, $obj->getId());
         $affectedRows += PcTranslationPeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PcTranslationPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setLanguageId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setStringId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setString($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setUpdatedAt($arr[$keys[3]]);
     }
 }
Exemplo n.º 7
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this PcLanguage is new, it will return
  * an empty collection; or if this PcLanguage has previously
  * been saved, it will retrieve related PcTranslations from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in PcLanguage.
  */
 public function getPcTranslationsJoinPcString($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(PcLanguagePeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collPcTranslations === null) {
         if ($this->isNew()) {
             $this->collPcTranslations = array();
         } else {
             $criteria->add(PcTranslationPeer::LANGUAGE_ID, $this->id);
             $this->collPcTranslations = PcTranslationPeer::doSelectJoinPcString($criteria, $con, $join_behavior);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(PcTranslationPeer::LANGUAGE_ID, $this->id);
         if (!isset($this->lastPcTranslationCriteria) || !$this->lastPcTranslationCriteria->equals($criteria)) {
             $this->collPcTranslations = PcTranslationPeer::doSelectJoinPcString($criteria, $con, $join_behavior);
         }
     }
     $this->lastPcTranslationCriteria = $criteria;
     return $this->collPcTranslations;
 }
 /**
  * Retrieve object using using composite pkey values.
  * @param      string $language_id
  * @param      string $string_id
  * @param      PropelPDO $con
  * @return     PcTranslation
  */
 public static function retrieveByPK($language_id, $string_id, PropelPDO $con = null)
 {
     $key = serialize(array((string) $language_id, (string) $string_id));
     if (null !== ($obj = PcTranslationPeer::getInstanceFromPool($key))) {
         return $obj;
     }
     if ($con === null) {
         $con = Propel::getConnection(PcTranslationPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $criteria = new Criteria(PcTranslationPeer::DATABASE_NAME);
     $criteria->add(PcTranslationPeer::LANGUAGE_ID, $language_id);
     $criteria->add(PcTranslationPeer::STRING_ID, $string_id);
     $v = PcTranslationPeer::doSelect($criteria, $con);
     return !empty($v) ? $v[0] : null;
 }