예제 #1
0
 public function execute()
 {
     require_once dmOs::join(sfConfig::get('dm_core_dir'), 'lib/vendor/Zend/Reflection/File.php');
     require_once dmOs::join(sfConfig::get('dm_core_dir'), 'lib/vendor/Zend/CodeGenerator/Php/File.php');
     require_once dmOs::join(sfConfig::get('dm_core_dir'), 'lib/vendor/dmZend/CodeGenerator/Php/Class.php');
     $file = dmOs::join($this->moduleDir, 'actions/actions.class.php');
     if (!$this->filesystem->mkdir(dirname($file))) {
         $this->logError('can not create directory ' . dmProject::unrootify(dirname($file)));
     }
     $className = $this->module->getKey() . 'Actions';
     if (file_exists($file)) {
         if ($this->shouldSkip($file)) {
             $this->log('skip ' . dmProject::unrootify($file));
             return true;
         }
         include_once $file;
         $this->class = dmZendCodeGeneratorPhpClass::fromReflection(new Zend_Reflection_Class($className));
         foreach ($this->class->getMethods() as $method) {
             $method->setIndentation($this->indentation);
         }
     } else {
         $this->class = $this->buildClass($className);
     }
     $this->class->setIndentation($this->indentation);
     if ($this->module->hasModel()) {
         foreach ($this->module->getComponents() as $component) {
             if ($component->getType() == 'form') {
                 $methodName = 'execute' . dmString::camelize($component->getKey()) . 'Widget';
                 if (!$this->class->getMethod($methodName)) {
                     $this->class->setMethod($this->buildFormMethod($methodName, $component));
                 }
             }
         }
     }
     if ($code = $this->class->generate()) {
         $return = file_put_contents($file, "<?php\n" . $code);
         $this->filesystem->chmod($file, 0777);
     } else {
         $return = true;
     }
     if (!$return) {
         $this->logError('can not write to ' . dmProject::unrootify($file));
     }
     return $return;
 }
 public function execute()
 {
     $dir = dmOs::join($this->moduleDir, 'templates');
     if (!$this->filesystem->mkdir($dir)) {
         $this->logError('can not create directory ' . $dir);
     }
     $success = true;
     foreach ($this->module->getComponents() as $component) {
         $file = dmOs::join($dir, '_' . $component->getKey() . '.php');
         if (file_exists($file)) {
             continue;
         }
         touch($file);
         $code = $this->getActionTemplate($component);
         $fileSuccess = file_put_contents($file, $code);
         $this->filesystem->chmod($file, 0777);
         if (!$fileSuccess) {
             $this->logError('can not write to ' . dmProject::unrootify($file));
         }
         $success &= $fileSuccess;
     }
     return $success;
 }
예제 #3
0
파일: dmDataLoad.php 프로젝트: jwegner/diem
 protected function loadI18nTransUnit()
 {
     foreach ($this->i18n->getCultures() as $culture) {
         if ($culture == sfConfig::get('sf_default_culture', 'en')) {
             continue;
         }
         /*
          * English to $culture
          */
         $catalogue = dmDb::table('DmCatalogue')->retrieveBySourceTargetSpace(sfConfig::get('sf_default_culture', 'en'), $culture, 'dm');
         $dataFiles = $this->configuration->getConfigPaths('data/dm/i18n/en_' . $culture . '.yml');
         $table = dmDb::table('DmTransUnit');
         $existQuery = $table->createQuery('t')->select('t.id, t.source, t.target, t.created_at, t.updated_at')->where('t.dm_catalogue_id = ? AND t.source = ?');
         $catalogueId = $catalogue->get('id');
         $nbAdded = 0;
         $nbUpdated = 0;
         foreach ($dataFiles as $dataFile) {
             if (!is_array($data = sfYaml::load(file_get_contents($dataFile)))) {
                 continue;
             }
             $addedTranslations = new Doctrine_Collection($table);
             $line = 0;
             foreach ($data as $source => $target) {
                 ++$line;
                 if (!is_string($source) || !is_string($target)) {
                     $this->log('Error line ' . $line . ': ' . dmProject::unrootify($dataFile));
                 } else {
                     $existing = $existQuery->fetchOneArray(array($catalogueId, $source));
                     if (!empty($existing) && $existing['source'] === $source) {
                         if ($existing['target'] !== $target) {
                             //$this->log(sprintf('%s -> %s', $existing['target'], $target));
                             // don't overwrite user modified translations
                             if ($existing['created_at'] === $existing['updated_at']) {
                                 $table->createQuery()->update('DmTransUnit')->set('target', '?', array($target))->where('id = ?', $existing['id'])->execute();
                                 ++$nbUpdated;
                             }
                         }
                     } elseif (empty($existing)) {
                         $addedTranslations->add(dmDb::create('DmTransUnit', array('dm_catalogue_id' => $catalogue->get('id'), 'source' => $source, 'target' => $target)));
                         ++$nbAdded;
                     }
                 }
             }
             $addedTranslations->save();
         }
         if ($nbAdded) {
             $this->log(sprintf('%s: added %d translation(s)', $culture, $nbAdded));
         }
         if ($nbUpdated) {
             $this->log(sprintf('%s: updated %d translation(s)', $culture, $nbUpdated));
         }
     }
 }
예제 #4
0
echo _open('div.dm_sitemap_tabs.mt10');
echo _open('ul');
foreach ($sitemap->getFiles() as $file) {
    echo _tag('li', _tag('a href=#dm_sitemap_' . dmString::slugify(basename($file)), basename($file)));
}
echo _close('ul');
foreach ($sitemap->getFiles() as $file) {
    echo _open('div#dm_sitemap_' . dmString::slugify(basename($file)));
    if (file_exists($file)) {
        echo _tag('div.clearfix.mb10', definition_list(array('Position' => _link($sitemap->getWebPath($file)), 'Urls' => $sitemap->countUrls($file), 'Size' => $sitemap->getFileSize($file), 'Updated at' => format_date($sitemap->getUpdatedAt($file))), '.clearfix.dm_little_dl.fleft.mr20'));
        echo _tag('pre', array('style' => 'background: #fff; padding: 10px; border: 1px solid #ddd; max-height: 350px; overflow-y: auto;'), htmlentities(file_get_contents($file), ENT_QUOTES, 'UTF-8'));
    } else {
        echo sprintf('<input type="submit" class="dm_sitemap_generate" value="%s" />', __('Generate sitemap'));
    }
    if (!is_writable($file)) {
        echo _tag('p.error', __('File %1% is not writable', array('%1%' => dmProject::unrootify($file))));
    }
    echo _close('div');
}
echo _close('div');
if (isset($phpCli)) {
    echo _open('div.dm_box.big.search_engine');
    echo _tag('h1.title', __('Set up a cron to update the sitemap'));
    echo _open('div.dm_box_inner.documentation');
    echo _tag('p', __('Most UNIX and GNU/Linux systems allows for task planning through a mechanism known as cron. The cron checks a configuration file (a crontab) for commands to run at a certain time.'));
    echo _tag('p.mt10.mb10', __('Open %1% and add the line:', array('%1%' => '/etc/crontab')));
    echo _tag('code', _tag('pre', sprintf('@daily %s %s %s/symfony dm:sitemap-update %s', $shellUser, $phpCli, $rootDir, $domainName)));
    echo _tag('p.mt10', __('For more information on the crontab configuration file format, type man 5 crontab in a terminal.'));
    echo _close('div');
    echo _close('div');
}