public function getDocument() { if (!$this->shouldIndex()) { $this->getSearch()->getEventDispatcher()->notify(new sfEvent($this, 'indexer.log', array('model "%s" cancelled indexation - primary key = %s', $this->getModelName(), current($this->getModel()->identifier())))); return false; } $old_culture = null; // automatic symfony i18n detection if ($this->getModel()->getTable()->hasRelation('Translation')) { $old_culture = sfDoctrineRecord::getDefaultCulture(); sfDoctrineRecord::setDefaultCulture($this->getSearch()->getParameter('culture')); } // build document $doc = $this->getBaseDocument(); $doc = $this->configureDocumentFields($doc); //$doc = $this->configureDocumentCategories($doc); $doc = $this->configureDocumentMetas($doc); // add document $doc->setField('sfl_guid', $this->getModelGuid()); // restore culture in symfony i18n detection if ($old_culture) { sfDoctrineRecord::setDefaultCulture($old_culture); } return $doc; }
/** * Update changed documentation pages in database */ protected function updateDatabase($branch) { $types = dmDb::query('Doc d')->select('d.type')->distinct()->fetchFlat(); $cultures = sfConfig::get('dm_i18n_cultures'); $originalCulture = sfDoctrineRecord::getDefaultCulture(); foreach ($types as $type) { foreach ($cultures as $culture) { sfDoctrineRecord::setDefaultCulture($culture); $dir = dmOs::join($this->repo->getDir(), $type, $culture); $files = sfFinder::type('file')->name('/^\\d{2}\\s-\\s.+\\.markdown$/')->in($dir); foreach ($files as $file) { $docName = preg_replace('/^\\d{2}\\s-\\s(.+)\\.markdown$/', '$1', basename($file)); $docRecord = dmDb::query('DocPage dp')->withI18n()->innerJoin('dp.Doc doc')->innerJoin('doc.Branch branch')->where('branch.number = ?', $branch)->andWhere('doc.type = ?', $type)->andWhere('dpTranslation.name = ?', $docName)->fetchOne(); if ($docRecord) { $docText = file_get_contents($file); if ($docRecord->text != $docText) { $docRecord->text = $docText; $docRecord->save(); } } } } } sfDoctrineRecord::setDefaultCulture($originalCulture); }
<?php include_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; include_once dirname(__FILE__) . '/../../../bootstrap/database.php'; sfContext::createInstance($configuration); sfDoctrineRecord::setDefaultCulture('ja_JP'); $t = new lime_test(5, new lime_output_color()); //------------------------------------------------------------ $t->diag('NotificationMailTable'); $t->diag('NotificationMailTable::getDisabledNotificationNames()'); $result = Doctrine::getTable('NotificationMail')->getDisabledNotificationNames(); $t->is($result, array('name2')); $t->diag('NotificationMailTable::fetchTemplate()'); $result = Doctrine::getTable('NotificationMail')->fetchTemplate('name1'); $t->isa_ok($result, 'NotificationMail'); $result = Doctrine::getTable('NotificationMail')->fetchTemplate('pc_changeMailAddress'); $t->isa_ok($result, 'NotificationMail'); $result = Doctrine::getTable('NotificationMail')->fetchTemplate('aaaaa'); $t->cmp_ok(false, '===', $result); $t->diag('NotificationMailTable::getConfigs()'); $result = Doctrine::getTable('NotificationMail')->getConfigs(); $t->isa_ok($result, 'array');
public function setCulture($culture) { sfDoctrineRecord::setDefaultCulture($culture); return $this->get('/', array('sf_culture' => $culture)); }