Example #1
0
 public function executeAssociations(dmDoctrineTable $table)
 {
     foreach ($table->getRelationHolder()->getAssociations() as $association) {
         $refTable = $association->getAssociationTable();
         $nbAssociations = $this->getOption('nb_records') * min(2, $association->getTable()->count());
         try {
             $availableIds = $this->getAvailableIdsByLocalAlias($refTable);
         } catch (dmRecordException $e) {
             // no available records
             break;
         }
         $createdPairs = $this->getExistingRelRecordPairs($refTable);
         $collection = new myDoctrineCollection($refTable);
         $iterations = 0;
         while (count($createdPairs) < $nbAssociations) {
             // avoid infinite loop
             if (++$iterations > 1000) {
                 break;
             }
             $vals = array();
             foreach ($refTable->getRelationHolder()->getLocals() as $relationAlias => $relation) {
                 $vals[$relation->getLocalColumnName()] = array_rand($availableIds[$relationAlias]);
             }
             if (!in_array($vals, $createdPairs)) {
                 //check if association does not already exists
                 $collection->add($refTable->create($vals));
                 $createdPairs[] = $vals;
             }
         }
         if ($collection->count()) {
             $collection->save();
         }
     }
 }
Example #2
0
 protected function createPageTranslations($pageId)
 {
     $cultures = $this->getOption('cultures');
     $translationTable = dmDb::table('DmPageTranslation');
     $existingCultures = $translationTable->createQuery('t')->where('t.id = ? ', $pageId)->andWhereIn('t.lang', $cultures)->select('t.lang')->fetchFlat();
     // can not generate translations from nothing
     if (empty($existingCultures)) {
         return;
     }
     // calculate missing cultures for this page
     $missingCultures = array_diff($cultures, $existingCultures);
     // all translations exist
     if (empty($missingCultures)) {
         return;
     }
     if (in_array(sfConfig::get('sf_default_culture'), $existingCultures)) {
         $mainCulture = sfConfig::get('sf_default_culture');
     } elseif (in_array(myDoctrineRecord::getDefaultCulture(), $existingCultures)) {
         $mainCulture = myDoctrineRecord::getDefaultCulture();
     } else {
         $mainCulture = dmArray::first($existingCultures);
     }
     $mainTranslationArray = $translationTable->createQuery('t')->select('t.slug, t.name, t.title, t.h1, t.description, t.keywords, t.is_active')->where('t.id = ?', $pageId)->andWhere('t.lang = ?', $mainCulture)->limit(1)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
     $missingTranslations = new myDoctrineCollection(dmDb::table('DmPageTranslation'));
     if ($this->getOption('activate_new_translations')) {
         $isActive = $mainTranslationArray['is_active'];
     } else {
         $isActive = false;
     }
     foreach ($missingCultures as $culture) {
         $missingTranslations->add($translationTable->create(array_merge($mainTranslationArray, array('lang' => $culture, 'is_active' => $isActive))));
     }
     $missingTranslations->save();
 }
 protected function copyI18nModel($model)
 {
     $table = dmDb::table($model);
     $this->log('Empty ' . $model);
     $table->createQuery()->delete()->execute();
     $records = new myDoctrineCollection($table);
     $this->log('Copy ' . $model);
     foreach ($this->oldDb->getData($table->getTableName()) as $array) {
         $records->add($table->create(array_merge($array, array('lang' => 'en'))));
     }
     $records->save();
 }
Example #4
0
 protected function loadPermissions()
 {
     $array = array("system" => "System administrator", "admin" => "Log into administration", "clear_cache" => "Clear the cache", "log" => "Manage logs", 'code_editor' => 'Use admin and front code editors', "security_user" => "Manage security users", "security_permission" => "Manage security permissions", "security_group" => "Manage security groups", "content" => "CRUD dynamic content in admin", "zone_add" => "Add zones", "zone_edit" => "Edit zones", "zone_delete" => "Delete zones", "widget_add" => "Add widgets", "widget_edit" => "Edit widgets", "widget_delete" => "Delete widgets", 'widget_edit_fast' => 'Can fast edit widgets', 'widget_edit_fast_record' => 'Fast edit widget record', 'widget_edit_fast_content_title' => 'Fast edit widget content title', 'widget_edit_fast_content_link' => 'Fast edit widget content link', 'widget_edit_fast_content_image' => 'Fast edit widget content image', 'widget_edit_fast_content_text' => 'Fast edit widget content text', 'widget_edit_fast_navigation_menu' => 'Fast edit widget navigation menu', "page_add" => "Add pages", "page_edit" => "Edit pages", "page_delete" => "Delete pages", "page_bar_admin" => "See page bar in admin", "media_bar_admin" => "See media bar in admin", "media_library" => "Use media library in admin", "media_ignore_whitelist" => "Upload media with any filetype", "tool_bar_admin" => "See toolbar in admin", "page_bar_front" => "See page bar in front", "media_bar_front" => "See media bar in front", "tool_bar_front" => "See toolbar in front", "site_view" => "See non-public website and inactive pages", "loremize" => "Create automatic random content", "export_table" => "Export table contents", "sitemap" => "Regenerate sitemap", "automatic_metas" => "Configure automatic pages metas", "manual_metas" => "Configure manually pages metas", "manage_pages" => "Move and sort pages", 'url_redirection' => 'Configure url redirections', "use_google_analytics" => "Use google analytics", "google_analytics" => "Configure google analytics", "use_google_webmaster_tools" => "Use google webmaster tools", "google_webmaster_tools" => "Configure google webmaster tools", "xiti" => "Configure Xiti", "search_engine" => "Manage internal search engine", "see_log" => "See the logs", 'see_chart' => 'See the charts', 'see_diagrams' => 'See the developer diagrams', 'see_server' => 'See the server infos', 'see_request' => 'See the requests window', 'see_event' => 'See the events window', "config_panel" => "Use the configuration panel", "translation" => "Use the translation interface", "layout" => "Use the layout interface", 'sent_mail' => 'See mails sent by server', 'mail_template' => 'Configure mail templates', 'error_log' => 'See error log', 'interface_settings' => 'Manage interface settings like default image resize method');
     $existingPermissions = dmDb::query('DmPermission p INDEXBY p.name')->select('p.name')->fetchArray();
     $addedPermissions = new myDoctrineCollection('DmPermission');
     foreach ($array as $name => $description) {
         if (!isset($existingPermissions[$name])) {
             $addedPermissions->add(dmDb::create('DmPermission', array('name' => $name, 'description' => $description)));
         }
     }
     $addedPermissions->save();
 }