示例#1
0
 public function executeModuleRecursive(dmModule $module, dmTableLoremizer $loremizer)
 {
     $loremizer->execute($module->getTable());
     foreach ($module->getChildren() as $child) {
         $this->executeModuleRecursive($child, $loremizer);
     }
 }
示例#2
0
 protected function updateModuleShowPagesRecursive(dmModule $module)
 {
     $moduleKey = $module->getKey();
     if (!$module->hasPage()) {
         foreach ($module->getChildren() as $child) {
             $this->updateModuleShowPagesRecursive($child);
         }
         return;
     }
     /*
      * prepares pages to update
      */
     $_showPages = dmDb::pdo('SELECT p.id, p.module, p.record_id, p.lft, p.rgt FROM dm_page p WHERE p.module = ? AND p.action = ?', array($moduleKey, 'show'))->fetchAll(PDO::FETCH_ASSOC);
     $showPages = array();
     foreach ($_showPages as $_showPage) {
         $showPages[$_showPage['record_id']] = $_showPage;
     }
     if ($module->hasListPage()) {
         $parentModule = $module;
         /*
          * prepare records
          */
         // http://github.com/diem-project/diem/issues#issue/182
         if (count($module->getTable()->getOption('inheritanceMap'))) {
             $records = $module->getTable()->createQuery('r')->select('r.id')->fetchArray();
         } else {
             $records = dmDb::pdo('SELECT r.id FROM ' . $module->getTable()->getTableName() . ' r')->fetchAll(PDO::FETCH_ASSOC);
         }
         /*
          * prepare parent pages
          */
         $parentPageIds = dmDb::pdo('SELECT p.id FROM dm_page p WHERE p.module = ? AND p.action = ?', array($moduleKey, 'list'))->fetch(PDO::FETCH_NUM);
         $parentPageIds = $parentPageIds[0];
         if (!$parentPageIds) {
             throw new dmException(sprintf('%s needs a parent page, %s.%s, but it does not exists', $module, $moduleKey, 'list'));
         }
         $parentRecordIds = false;
     } else {
         if (!($parentModule = $module->getNearestAncestorWithPage())) {
             throw new dmException(sprintf('%s module is child of %s module, but %s module has no ancestor with page', $module, $parentModule, $module));
         }
         /*
          * prepare records
          */
         $select = 'r.id';
         if ($module->hasLocal($module->getParent())) {
             $select .= ', r.' . $module->getTable()->getRelationHolder()->getLocalByClass($module->getParent()->getModel())->getLocal();
         }
         // http://github.com/diem-project/diem/issues#issue/182
         if (count($module->getTable()->getOption('inheritanceMap'))) {
             $records = $module->getTable()->createQuery('r')->select($select)->fetchArray();
         } else {
             $records = dmDb::pdo('SELECT ' . $select . ' FROM ' . $module->getTable()->getTableName() . ' r')->fetchAll(PDO::FETCH_ASSOC);
         }
         /*
          * prepare parent pages
          */
         $_parentPageIds = dmDb::pdo('SELECT p.id, p.record_id FROM dm_page p WHERE p.module = ? AND p.action = ?', array($parentModule->getKey(), 'show'))->fetchAll(PDO::FETCH_NUM);
         $parentPageIds = array();
         foreach ($_parentPageIds as $value) {
             $parentPageIds[$value[1]] = $value[0];
         }
         $parentRecordIds = $this->getParentRecordIds($module, $parentModule);
     }
     foreach ($records as $record) {
         if (isset($showPages[$record['id']])) {
             $page = $showPages[$record['id']];
         } else {
             $page = array('id' => null, 'record_id' => $record['id'], 'module' => $moduleKey, 'action' => 'show');
         }
         try {
             $this->updatePageFromRecord($page, $record, $module, $parentModule, $parentPageIds, $parentRecordIds);
         } catch (dmPageMustNotExistException $e) {
             if ($page['id']) {
                 dmDb::table('DmPage')->find($page['id'])->getNode()->delete();
             }
         }
     }
     foreach ($module->getChildren() as $child) {
         $this->updateModuleShowPagesRecursive($child);
     }
 }