Ejemplo n.º 1
0
 public function setRecord(dmDoctrineRecord $record)
 {
     if ($record->getDmModule()->getKey() != $this->get('module')) {
         throw new dmException('Assigning record with wrong module');
     }
     return $this->setCache('record', $record);
 }
 protected function manageInsert(dmDoctrineRecord $record, $actionName, $actionConfig, $app)
 {
     $permission = new DmRecordPermission();
     $permission->set('secure_module', $record->getDmModule()->getSfName());
     $permission->set('secure_action', $actionName);
     $permission->set('secure_model', get_class($record));
     $permission->set('secure_record', $record->get($record->getTable()->getIdentifier()));
     $permission->set('description', sprintf('Secure access to action %s of module %s for record "%s" of class %s', $actionName, $record->getDmModule()->getKey(), $record->__toString(), get_class($record)));
     $permission->save();
 }
Ejemplo n.º 3
0
 protected function replace(dmDoctrineRecord $record, array $fields)
 {
     foreach ($fields as $field) {
         $oldValue = $record->get($field);
         $newValue = strtr($oldValue, $this->getReplacements());
         if ($oldValue != $newValue) {
             $this->log('Correct ' . $record . '->' . $field);
             $record->set($field, $newValue);
             $record->save();
         }
     }
 }
Ejemplo n.º 4
0
 public function getMediaUrl(dmDoctrineRecord $record)
 {
     if ($record instanceof DmMediaFolder) {
         if (null === $this->mediaFolderPathBaseUrl) {
             $this->mediaFolderPathBaseUrl = $this->generate('dm_media_library_path', array('path' => '__DM_MEDIA_PATH_PLACEHOLDER__'));
         }
         return str_replace('__DM_MEDIA_PATH_PLACEHOLDER__', $record->getRelPath(), $this->mediaFolderPathBaseUrl);
     } elseif ($record instanceof DmMedia) {
         return 'dmMediaLibrary/file?media_id=' . $record->get('id');
     } else {
         throw new dmException('Can not generate url for ' . $record);
     }
 }
Ejemplo n.º 5
0
 public function addModifiedRecord(dmDoctrineRecord $record)
 {
     if ($record instanceof DmAutoSeo) {
         $table = $record->getTargetDmModule()->getTable();
     } else {
         $table = $record->getTable();
     }
     if ($table instanceof dmDoctrineTable) {
         if (!isset($this->modifiedTables[$table->getComponentName()]) && $table->interactsWithPageTree()) {
             $this->addModifiedTable($table);
         }
     }
     return $this;
 }
Ejemplo n.º 6
0
 protected function initialize(array $options = array())
 {
     $this->configure($options);
     sfConfig::set('sf_logging_enabled', false);
     $culture = $this->getOption('culture');
     sfConfig::set('sf_default_culture', $culture);
     dmDoctrineRecord::setDefaultCulture($culture);
     dmConfig::setCulture($culture);
 }
Ejemplo n.º 7
0
 public function execute($threadClass, array $threadOptions = array())
 {
     if (!isset($threadOptions['culture'])) {
         $threadOptions['culture'] = dmDoctrineRecord::getDefaultCulture();
     }
     $command = $this->getCommand($threadClass, $threadOptions);
     if (!$this->filesystem->exec($command)) {
         throw new dmThreadException(sprintf("Thread %s failed ( app: %s, env: %s )\ncommand : %s\nmessage : %s", $threadClass, $this->options['app'], $this->options['env'], $this->getLastExec('command'), $this->getLastExec('output')));
     }
 }
Ejemplo n.º 8
0
 /**
  * Will join all relations
  * @return myDoctrineQuery
  */
 public function joinAll(dmDoctrineQuery $query = null)
 {
     if ($query instanceof dmDoctrineQuery) {
         $rootAlias = $query->getRootAlias();
     } else {
         $query = $this->createQuery($rootAlias = 'q');
     }
     foreach ($this->getRelationHolder()->getAll() as $relation) {
         if ($relation->getAlias() === 'Version' && $this->isVersionable()) {
             continue;
         } elseif ($relation->getAlias() === 'Translation') {
             $query->withI18n();
         } elseif ($relation->getClass() === 'DmMedia') {
             if ($relation instanceof Doctrine_Relation_Association && $this->hasTemplate('DmGallery')) {
                 continue;
             }
             $query->withDmMedia($relation->getAlias());
         } else {
             if ($relation instanceof Doctrine_Relation_ForeignKey) {
                 if ($this->getRelationHolder()->getAssociationByRefClass($relation->getClass())) {
                     continue;
                 }
             }
             $joinAlias = dmString::lcfirst($relation->getAlias());
             $query->leftJoin(sprintf('%s.%s %s', $rootAlias, $relation->getAlias(), $joinAlias));
             if ($relation->getTable()->hasRelation('Translation')) {
                 $joinI18nAlias = $joinAlias . 'Translation';
                 $query->leftJoin(sprintf('%s.%s %s WITH %s.lang = ?', $joinAlias, 'Translation', $joinI18nAlias, $joinI18nAlias), dmDoctrineRecord::getDefaultCulture());
             }
         }
     }
     return $query;
 }
Ejemplo n.º 9
0
 public function getReplacementsForPatterns(dmProjectModule $module, array $patterns, dmDoctrineRecord $record)
 {
     $moduleKey = $module->getKey();
     $replacements = array();
     foreach ($this->getPatternsPlaceholders($patterns) as $placeholder) {
         if ('culture' === $placeholder || 'user.culture' === $placeholder) {
             $replacements[$this->wrap($placeholder)] = $this->culture;
             continue;
         }
         /*
          * Extract model and field from 'model.field' or 'model'
          */
         if (strpos($placeholder, '.')) {
             list($usedModuleKey, $field) = explode('.', $placeholder);
         } else {
             $usedModuleKey = $placeholder;
             $field = '__toString';
         }
         $usedModuleKey = dmString::modulize($usedModuleKey);
         $usedRecord = null;
         /*
          * Retrieve used record
          */
         if ($usedModuleKey === $moduleKey) {
             $usedRecord = $record;
         } elseif ($module->hasAncestor($usedModuleKey)) {
             $usedRecord = $record->getAncestorRecord($module->getAncestor($usedModuleKey)->getModel());
         } else {
             $usedRecord = $record->getRelatedRecord($this->moduleManager->getModule($usedModuleKey)->getModel());
         }
         if ($usedRecord instanceof dmDoctrineRecord) {
             /*
              * get record value for field
              */
             if ($field === '__toString') {
                 $usedValue = $usedRecord->__toString();
                 $processMarkdown = true;
             } else {
                 try {
                     $usedValue = $usedRecord->get($field);
                 } catch (Doctrine_Record_UnknownPropertyException $e) {
                     $usedValue = $usedRecord->{'get' . dmString::camelize($field)}();
                 }
                 $processMarkdown = $this->shouldProcessMarkdown($usedRecord->getTable(), $field);
             }
             unset($usedRecord);
         } else {
             $usedValue = $moduleKey . '-' . $usedModuleKey . ' not found';
             $processMarkdown = false;
         }
         $usedValue = trim($usedValue);
         if ($processMarkdown) {
             $usedValue = dmMarkdown::brutalToText($usedValue);
         }
         $replacements[$this->wrap($placeholder)] = $usedValue;
     }
     return $replacements;
 }
Ejemplo n.º 10
0
 /**
  * Create current i18n form
  */
 protected function createI18nForm($culture = null)
 {
     if (!$this->isI18n()) {
         throw new dmException(sprintf('The model "%s" is not internationalized.', $this->getModelName()));
     }
     $i18nFormClass = $this->getI18nFormClass();
     $culture = null === $culture ? dmDoctrineRecord::getDefaultCulture() : $culture;
     // translation already set, use it
     if ($this->object->get('Translation')->contains($culture)) {
         $translation = $this->object->get('Translation')->get($culture);
     } else {
         $translation = $this->object->get('Translation')->get($culture);
         // populate new translation with fallback values
         if (!$translation->exists()) {
             if ($fallback = $this->object->getI18nFallBack()) {
                 $fallBackData = $fallback->toArray();
                 unset($fallBackData['id'], $fallBackData['lang']);
                 $translation->fromArray($fallBackData);
             }
         }
     }
     $i18nForm = new $i18nFormClass($translation);
     unset($i18nForm['id'], $i18nForm['lang']);
     return $i18nForm;
 }
Ejemplo n.º 11
0
 public function findOneByRecordWithI18n(dmDoctrineRecord $record)
 {
     $module = $record->getDmModule()->getKey();
     if (isset($this->recordPageCache[$module][$record->get('id')])) {
         return $this->recordPageCache[$module][$record->get('id')];
     }
     return $this->createQuery('p')->where('p.module = ?', $module)->andWhere('p.action = ?', 'show')->andWhere('p.record_id = ?', $record->get('id'))->withI18n(null, null, 'p')->fetchOne();
 }
Ejemplo n.º 12
0
 protected function getRandomLink()
 {
     if (mt_rand(0, 1)) {
         return sprintf('http://' . dmString::random() . '.random.com');
     }
     if (!class_exists('DmPageTranslation', false)) {
         new DmPage();
     }
     $page = dmDb::query('DmPageTranslation p')->select('p.id, p.name, p.lang, RANDOM() AS rand')->where('p.lang = ?', dmDoctrineRecord::getDefaultCulture())->orderBy('rand')->limit(1)->fetchPDO();
     return sprintf('page:%d %s', $page[0][0], $page[0][1]);
 }
Ejemplo n.º 13
0
 public function clearClassCache($cacheKey = null)
 {
     if (null === $cacheKey) {
         self::$classCache = array();
     } elseif (isset(self::$classCache[$cacheKey])) {
         unset(self::$classCache[$cacheKey]);
     }
     return $this;
 }
 protected function getDefaultConfig()
 {
     return array_merge(array('language' => dmDoctrineRecord::getDefaultCulture()), sfConfig::get('dm_ckeditor_config'));
 }