Beispiel #1
0
 /**
  * @param bool $return
  * @return array
  */
 public static function check($return = false)
 {
     $must_migrate = false;
     $return_data = array();
     foreach (Core_Files::listFiles(cfg()->migration_path) as $migration_file) {
         if (strstr($migration_file, self::TEMPLATE_NAME)) {
             continue;
         }
         $migration_data = explode(DS, $migration_file);
         list($migration_file_name) = array_reverse($migration_data);
         list($migration_name, $extension) = explode('.', $migration_file_name);
         $migration_class_name = self::MIGRATION_PREFIX . $migration_name . self::MIGRATION_SUFIX;
         /* @var $migration_object Core_Migration_Abstract */
         $migration_object = new $migration_class_name();
         if ($migration_object->check()) {
             $must_migrate = true;
             if ($return) {
                 $return_data[] = $migration_file_name;
             } else {
                 echo 'TO RUN: ' . $migration_file_name . PHP_EOL;
             }
         }
     }
     if (!$must_migrate) {
         if (!$return) {
             echo 'DB is UP TO DATE' . PHP_EOL;
         }
     }
     if ($return) {
         return $return_data;
     }
 }
Beispiel #2
0
 /**
  *
  */
 public function indexAction()
 {
     $argv = $this->getRequest()->getServer('argv');
     $test_to_run = isset($argv[3]) ? $argv[3] : Const_Tests::RUN_ALL_TESTS;
     $test_to_run = str_replace('_', '/', $test_to_run);
     foreach (Core_Files::listFiles(cfg()->tests_path) as $test) {
         if (!strstr($test, $test_to_run . '.php') && $test_to_run != Const_Tests::RUN_ALL_TESTS) {
             continue;
         }
         $class_path = str_replace(cfg()->tests_path, '', $test);
         $class_path_frag = explode('/', $class_path);
         $class_path_frag = array_map("ucfirst", $class_path_frag);
         $class_path_frag[count($class_path_frag) - 1] = str_replace('.php', '', $class_path_frag[count($class_path_frag) - 1]);
         $class = implode('_', $class_path_frag);
         $class_name = 'Tests_' . $class . 'File';
         echo '--------------------------------------' . PHP_EOL;
         echo 'Running test: ' . $class_name . PHP_EOL;
         echo '--------------------------------------' . PHP_EOL;
         $phpunit = new PHPUnit_TextUI_TestRunner();
         $phpunit->run($phpunit->getTest($class_name, $test), array('colors' => 'auto'));
         if ($test_to_run != Const_Tests::RUN_ALL_TESTS) {
             die;
         }
         echo PHP_EOL . PHP_EOL;
     }
     die;
 }
Beispiel #3
0
 /**
  *
  */
 public function indexAction()
 {
     die('todo');
     $overwrite = !is_null(Core_Request::getInstance()->getArgv(4)) ? Core_Request::getInstance()->getArgv(4) : false;
     foreach (dibi::getDatabaseInfo()->getTables() as $table_data) {
         if ($table_data->getName() == Migration_MigrationModel::getTableName()) {
             continue;
         }
         $ddl_data = dibi::query('SHOW CREATE TABLE ' . $table_data->getName())->fetch()->toArray();
         $ddl_query = $ddl_data['Create Table'];
         $migration_time = time();
         $migration_name = 'Create' . ucfirst($table_data->getName());
         $migration_name = str_replace(' ', '', $migration_name);
         $migration_name = str_replace('-', '', $migration_name);
         $migration_name = str_replace('_', '', $migration_name);
         $filename = cfg()->migration_path . $migration_name . '.php';
         if (Core_Files::fileSize($filename) && !$overwrite) {
             echo PHP_EOL . 'Migration "Create ' . ucfirst($table_data->getName()) . '" Exists' . PHP_EOL;
             continue;
         }
         $template_data = Core_Files::getContent(cfg()->migration_path . Migration_FilesHelper::TEMPLATE_FILE_NAME);
         $template_data = str_replace('Template', $migration_name, $template_data);
         $template_data = str_replace('__NAME__', $migration_name, $template_data);
         $template_data = str_replace('__CREATED_AT__', $migration_time, $template_data);
         $template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data);
         $template_data = preg_replace('#//__UP_ACTION__#', $ddl_query, $template_data);
         $down_query = 'DROP TABLE IF EXISTS `' . $table_data->getName() . '`';
         $template_data = preg_replace('#//__DOWN_ACTION__#', $down_query, $template_data);
         Core_Files::putContent($filename, $template_data);
         echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL;
     }
 }
Beispiel #4
0
 /**
  * @return array|bool|string
  */
 public static function getLoad()
 {
     if (!Core_Cache::get('server_load')) {
         if (is_file(self::LOAD_FILE)) {
             $file_source = (double) Core_Files::getContent(self::LOAD_FILE);
             list($server_load) = explode(' ', $file_source);
             Core_Cache::set('server_load', $server_load, 60);
         }
     }
     return Core_Cache::get('server_load');
 }
Beispiel #5
0
 /**
  * @throws Exception
  */
 public function indexAction()
 {
     $migration_time = time();
     $migration_name = time();
     if (!$migration_name) {
         throw new Exception('No migration name given');
     }
     $filename = cfg()->migration_path . $migration_name . '.php';
     if (Core_Files::fileSize($filename)) {
         throw new Exception('Migration with that name exists');
     }
     $template_data = Core_Files::getContent(cfg()->migration_path . Const_Migrations::TEMPLATE_FILE_NAME);
     $template_data = str_replace('Template', $migration_name, $template_data);
     $template_data = str_replace('__NAME__', $migration_name, $template_data);
     $template_data = str_replace('__CREATED_AT__', $migration_time, $template_data);
     $template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data);
     Core_Files::putContent($filename, $template_data);
     echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL . PHP_EOL;
 }
Beispiel #6
0
 protected function getFilesTags($dir)
 {
     $files = Core_Files::listFiles($dir, true);
     foreach ($files as $file) {
         $extension = Core_Files::getExtension($file);
         if (in_array($extension, array('phtml', 'php'))) {
             $content = Core_Files::getContent($file);
             if (empty($content)) {
                 continue;
             }
             preg_match_all('/__(\\(\'|\\("|\\()(.*?)(\'\\)|\\"\\)|\\)\'|\\)"|",|\',)/', $content, $matches);
             if ($matches[2]) {
                 foreach ($matches[2] as $tag) {
                     if (substr($tag, 0, 1) == '$') {
                         continue;
                     }
                     $this->tags[] = array('tag' => strtolower($tag), 'location' => $file);
                 }
             }
         }
     }
 }
Beispiel #7
0
 /**
  * @param       $hash_id
  * @param array $files
  * @return null|string
  */
 public static function css($hash_id, array $files)
 {
     if (empty($files)) {
         return false;
     }
     $cache_name = '';
     foreach ($files as &$file) {
         $file = cfg()->static_path . 'css' . DS . $file;
         $cache_name .= Core_Files::fileSize($file);
     }
     unset($file);
     $f_name = md5($hash_id . $cache_name) . '.css';
     $f_path = cfg()->cache_path . 'css' . DS . $f_name;
     $f_public = cfg()->cache_address . 'css/' . $f_name;
     if (!is_file($f_path)) {
         // lets empty the directory
         $cache_files = Core_Files::listFiles(cfg()->cache_path . 'css' . DS);
         foreach ($cache_files as $cfile) {
             Core_Files::delete($cfile, true);
         }
         $css_content = '';
         foreach ($files as $file) {
             $content = Core_Files::getContent($file);
             $css_content .= $content;
         }
         $css_content = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $css_content);
         // Remove space after colons
         $css_content = str_replace(': ', ':', $css_content);
         // Remove whitespace
         $css_content = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $css_content);
         // now save the file
         Core_Files::putContent($f_path, $css_content);
     }
     return '<link type="text/css" rel="stylesheet" href="' . $f_public . '"/>';
 }
Beispiel #8
0
 /**
  * копируем папку со всем содержимым
  * $this->setPathFrom( 'local/path' )->setPathTo( 'path/on/ftp' )->dirUpload();
  * если _pathTo не установили то используем _root, если она тоже не установлена то процесс прерывается
  *
  * @param array $_arrSource - если массив пуст то система берёт файлы и папки из _pathFrom
  * @return boolean
  */
 public function dirUpload($_arrSource = array())
 {
     $_strDirTo = empty($this->_pathTo) ? $this->_root : $this->_pathTo;
     if (empty($_strDirTo)) {
         return false;
     }
     if (empty($_arrSource)) {
         if (!Core_Files::dirScan($_arrSource, $this->_pathFrom)) {
             return false;
         }
     }
     if (empty($this->_pathFrom)) {
         // если есть $_arrSource, $this->_pathFrom указывать необязательно TODO!!!15.04.2010
         return false;
     }
     $_int = strlen($this->_pathFrom);
     foreach ($_arrSource as $_strDir => $_arrFiles) {
         $_strDest = str_replace(array('\\', '//'), '/', $_strDirTo . substr($_strDir, $_int));
         if (!$this->changeOrMakeDir($_strDest)) {
             return false;
         }
         if (empty($_arrFiles)) {
             continue;
         }
         // теперь заливаем файлы в диру
         foreach ($_arrFiles as $v) {
             if (!$this->fileUpload($_strDest . '/' . $v, $_strDir . '/' . $v)) {
                 return false;
             }
         }
     }
     $this->_pathFrom = $this->_pathTo = '';
     return true;
 }