Пример #1
0
 /**
  * Receive the uploaded file
  *
  * @return boolean
  */
 public function receive()
 {
     $fileinfo = $this->getFileInfo();
     if (null === $this->_initialFilename) {
         $this->_initialFilename = $fileinfo[$this->getName()]['name'];
     }
     $dirName = md5(Centurion_Inflector::uniq($fileinfo[$this->getName()]['tmp_name']));
     $filename = substr($dirName, 0, 2) . DIRECTORY_SEPARATOR . substr($dirName, 2) . Centurion_Inflector::extension($fileinfo[$this->getName()]['name']);
     $this->_localFilename = $filename;
     if (!file_exists($this->getDestination() . DIRECTORY_SEPARATOR . substr($dirName, 0, 2))) {
         mkdir($this->getDestination() . DIRECTORY_SEPARATOR . substr($dirName, 0, 2), 0770, true);
     }
     $this->getTransferAdapter()->addFilter('Rename', array('target' => $this->getDestination() . DIRECTORY_SEPARATOR . $filename, 'overwrite' => true))->setOptions(array('useByteString' => false));
     // retrieve the real filesize
     return parent::receive();
 }
Пример #2
0
 /**
  * @dataProvider dataForTestExtensionFunction
  */
 public function testExtensionFunction($fileName, $withDot, $expectedResult)
 {
     $this->assertEquals($expectedResult, Centurion_Inflector::extension($fileName, $withDot));
 }
Пример #3
0
 /**
  * @param $env
  * @param bool $acceptAll
  * @param bool $ignoreLaunched
  * @throws Exception
  * @throws Centurion_Application_Resource_Exception
  *
  * @todo: rajouter la gestion des php
  * @todo: refractoring
  */
 public function update($env, $acceptAll = false, $ignoreLaunched = true)
 {
     if ($acceptAll === 'true') {
         $acceptAll = true;
     }
     if ($ignoreLaunched === 'true') {
         $ignoreLaunched = true;
     }
     if ($acceptAll === 'false') {
         $acceptAll = false;
     }
     if ($ignoreLaunched === 'false') {
         $ignoreLaunched = false;
     }
     $this->bootstrap($env);
     $application = $this->_application;
     $bootstrap = $application->getBootstrap();
     $front = $bootstrap->getResource('FrontController');
     $modules = $front->getControllerDirectory();
     $default = $front->getDefaultModule();
     $options = $bootstrap->getOption('resources');
     $options = $options['modules'];
     if (is_array($options) && !empty($options[0])) {
         $diffs = array_diff($options, array_keys($modules));
         if (count($diffs)) {
             throw new Centurion_Application_Resource_Exception(sprintf("The modules %s is not found in your registry (%s)", implode(', ', $diffs), implode(PATH_SEPARATOR, $modules)));
         }
         foreach ($modules as $key => $module) {
             if (!in_array($key, $options) && $key !== $default) {
                 unset($modules[$key]);
                 $front->removeControllerDirectory($key);
             }
         }
         $modules = Centurion_Inflector::sortArrayByArray($modules, array_values($options));
     }
     $db = Zend_Db_Table::getDefaultAdapter();
     foreach ($modules as $module => $moduleDirectory) {
         $modulePath = dirname($moduleDirectory);
         $dataPath = $modulePath . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
         echo $dataPath;
         if (is_dir($dataPath)) {
             echo 'Open ' . $dataPath . "\n";
             $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dataPath, FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_FILENAME));
             $files = iterator_to_array($files);
             ksort($files);
             $files = array_merge(array('schema.sql' => null, 'data.sql' => null), $files);
             foreach ($files as $file) {
                 if (null == $file) {
                     continue;
                 }
                 if ($file->isDir()) {
                     continue;
                 }
                 if (Centurion_Inflector::extension($file) !== '.sql') {
                     continue;
                 }
                 $choice = null;
                 if (file_exists($file->getPathname() . '.' . APPLICATION_ENV . '.done')) {
                     if ($ignoreLaunched) {
                         continue;
                     }
                     if (!$acceptAll) {
                         echo sprintf('The file %s seems to be already executed. Do you want to launch it?' . "\n", $file->getPathname());
                     }
                 }
                 if (!$acceptAll) {
                     echo sprintf('Find a new file file %s. Do you want to launch it?' . "\n", $file->getPathname());
                 } else {
                     $choice = '1';
                 }
                 if (null == $choice) {
                     do {
                         echo '1) Execute' . "\n";
                         echo '2) Ignore' . "\n";
                         echo '3) Mark it without execute it' . "\n";
                         echo '? ';
                         $choice = trim(fgets(STDIN));
                     } while (!in_array($choice, array('1', '2', '3')));
                 }
                 if ($choice == '2') {
                     echo "\n\n";
                     continue;
                 }
                 if ($choice == '1') {
                     echo sprintf('Exec the file %s' . "\n", $file->getPathname());
                     try {
                         $db->beginTransaction();
                         $query = '';
                         foreach (new SplFileObject($file->getPathname()) as $line) {
                             $query .= $line;
                             if (substr(rtrim($query), -1) == ';') {
                                 $statement = $db->query($query);
                                 $statement->closeCursor();
                                 unset($statement);
                                 $query = '';
                             }
                         }
                         $db->commit();
                     } catch (Exception $e) {
                         $db->rollback();
                         throw $e;
                     }
                 }
                 touch($file->getPathname() . '.' . APPLICATION_ENV . '.done');
                 echo "\n\n";
             }
         }
     }
     Centurion_Loader_PluginLoader::clean();
     Centurion_Signal::factory('clean_cache')->send($this);
 }