protected function writeFixture(dmModule $module, $securityDesc)
 {
     $this->clear();
     if ($pluginName = $module->getPluginName()) {
         $root = dmContext::getInstance()->getConfiguration()->getPluginConfiguration($pluginName)->getRootDir();
     } else {
         $root = sfConfig::get('sf_root_dir');
     }
     $fixturesRootPath = dmOs::join($root, 'data', 'fixtures');
     foreach (array('admin', 'front') as $app) {
         foreach (array('actions', 'components') as $actionKind) {
             if (isset($securityDesc[$app]) && isset($securityDesc[$app][$actionKind]) && is_array($securityDesc[$app][$actionKind])) {
                 foreach ($securityDesc[$app][$actionKind] as $actionName => $actionDesc) {
                     if (isset($actionDesc['credentials'])) {
                         $credentials = (array) $module->getSecurityManager()->parseCredentials($actionDesc['credentials']);
                         foreach ($credentials as $credential) {
                             $this->addPermissionFor($credential, $module->getKey(), $actionName);
                         }
                     }
                 }
             }
         }
     }
     $this->doWriteFixture(dmOs::join($fixturesRootPath, 'DmPermissions', $module->getKey() . '.yml'));
 }
 protected function addFixtures(dmModule $module, $securityDesc)
 {
     foreach (array('admin', 'front') as $app) {
         foreach (array('actions', 'components') as $actionKind) {
             if (isset($securityDesc[$app]) && isset($securityDesc[$app][$actionKind]) && is_array($securityDesc[$app][$actionKind])) {
                 foreach ($securityDesc[$app][$actionKind] as $actionName => $actionDesc) {
                     if (isset($actionDesc['credentials'])) {
                         $credentials = (array) $module->getSecurityManager()->parseCredentials($actionDesc['credentials']);
                         foreach ($credentials as $credential) {
                             $this->addPermissionFor($credential, $module->getKey(), $actionName);
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 3
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);
     }
 }