예제 #1
0
 public function create($name = null, $type = null, $params = array())
 {
     if (is_null($name) and !is_null($type)) {
         $name = $type;
     }
     $name = 'h' . date('Ymd_His') . (!is_null($name) ? "_{$name}" : '');
     // get code for before
     if (!is_null($type) and method_exists($this, "create_before_for_{$type}")) {
         $code_before = call_user_func(array($this, "create_before_for_{$type}"), $params);
     } else {
         $code_before = '';
     }
     // get code for after
     if (!is_null($type) and method_exists($this, "create_after_for_{$type}")) {
         $code_after = call_user_func(array($this, "create_after_for_{$type}"), $params);
     } else {
         $code_after = '';
     }
     $content = "<?php\n        class {$name} {\n\n            // Run before patch\n            public function before() {\n                {$code_before}\n            }\n\n            // Run after patch\n            public function after() {\n                {$code_after}\n            }\n\n        }";
     $dir = fx::path('@floxim/update/hook');
     try {
         if (file_exists($dir)) {
             fx::files()->mkdir($dir);
         }
         fx::files()->writefile($dir . '/' . $name . '.php', $content);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
예제 #2
0
 public function create($name = null, $save_as_done = false)
 {
     $name = 'm' . date('Ymd_His') . (!is_null($name) ? "_{$name}" : '');
     $content = "<?php\n        class {$name} extends \\Floxim\\Floxim\\System\\Migration {\n\n            // Run for up migration\n            protected function up() {\n\n            }\n\n            // Run for down migration\n            protected function down() {\n\n            }\n\n        }";
     $dir = fx::path('@floxim/update/migration');
     try {
         if (file_exists($dir)) {
             fx::files()->mkdir($dir);
         }
         $target_file = $dir . '/' . $name . '.php';
         fx::files()->writefile($target_file, $content);
         if ($this->getParam('console')) {
             echo 'Successful!';
         }
         if ($save_as_done) {
             require_once $target_file;
             $migration = new $name();
             $migration->saveAsDone();
         }
         return true;
     } catch (Exception $e) {
         if ($this->getParam('console')) {
             echo 'Error: ' . $e->getMessage();
         }
         return false;
     }
 }
예제 #3
0
 protected function applyForcedParams()
 {
     if ($this->forced_params_loaded) {
         return;
     }
     $this->forced_params_loaded = true;
     $sig = str_replace(":", '__', $this->getSignature());
     $cache_file = fx::path('@files/cache/ctr_defaults_' . $sig . '.php');
     if (!fx::path()->exists($cache_file)) {
         $action = fx::util()->camelToUnderscore($this->action);
         $forced = array();
         $cfg = $this->getConfig();
         if (isset($cfg['actions'][$action]['force'])) {
             $forced = $cfg['actions'][$action]['force'];
         }
         fx::files()->writefile($cache_file, "<?php return " . var_export($forced, true) . ";");
     } else {
         $forced = (include $cache_file);
     }
     foreach ($forced as $param => $value) {
         $this->setParam($param, $value);
     }
 }
예제 #4
0
파일: Import.php 프로젝트: floxim/floxim
 /**
  * Импортирует файл из каталога импорта
  * Дополнительно проверяется соответствие по карте маппинга
  *
  * @param $file
  * @return string
  */
 protected function importFile($file)
 {
     $fileFullPath = $this->currentDir . DIRECTORY_SEPARATOR . $this->pathRelDataFile . $file;
     if (array_key_exists($fileFullPath, $this->mapFiles)) {
         return $this->mapFiles[$fileFullPath];
     }
     if (file_exists($fileFullPath)) {
         $fileName = pathinfo($file, PATHINFO_FILENAME);
         $filePath = pathinfo($file, PATHINFO_DIRNAME);
         $fileExt = pathinfo($file, PATHINFO_EXTENSION);
         $pathDest = fx::path($filePath) . DIRECTORY_SEPARATOR;
         $i = 0;
         $fileNameUniq = $fileName . '.' . $fileExt;
         /**
          * Формируем уникальное имя с проверкой на существование
          */
         while (file_exists($pathDest . $fileNameUniq)) {
             $i++;
             $fileNameUniq = $fileName . '_' . $i . '.' . $fileExt;
         }
         fx::files()->copy($fileFullPath, $pathDest . $fileNameUniq);
         /**
          * Возвращать нужно относительный путь
          */
         return $this->mapFiles[$fileFullPath] = $filePath . DIRECTORY_SEPARATOR . $fileNameUniq;
     }
     return null;
 }
예제 #5
0
파일: Export.php 프로젝트: floxim/floxim
 protected function exportFile($fileRel)
 {
     $pathSource = fx::path($fileRel);
     $pathDist = $this->pathExportTmp . DIRECTORY_SEPARATOR . $this->pathRelDataFile . $fileRel;
     if (file_exists($pathSource) and !file_exists($pathDist)) {
         fx::files()->copy($pathSource, $pathDist);
     }
 }
예제 #6
0
파일: Util.php 프로젝트: floxim/floxim
 /**
  * 
  */
 public function dumpSiteData($site_id = null, $target_file = null)
 {
     if (is_null($site_id)) {
         $site_id = fx::env('site_id');
     }
     if (is_null($target_file)) {
         $dir = '@files/export/site_' . $site_id;
         fx::files()->mkdir($dir);
         $target_file = fx::path()->abs($dir . '/data.sql');
     }
     // export the site
     fx::db()->dump(array('tables' => array('site'), 'where' => 'id = ' . $site_id, 'schema' => false, 'file' => $target_file));
     // export infoblocks
     fx::db()->dump(array('tables' => array('infoblock'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // export URL aliases
     fx::db()->dump(array('tables' => array('url_alias'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // export infoblock_visual
     $infoblock_ids = fx::data('infoblock')->where('site_id', $site_id)->all()->getValues('id');
     fx::db()->dump(array('tables' => array('infoblock_visual'), 'where' => 'infoblock_id IN (' . join(", ", $infoblock_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true));
     // export main content table
     fx::db()->dump(array('tables' => array('floxim_main_content'), 'where' => 'site_id  = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // get existing content items
     $items = fx::db()->getResults('select id, type from {{floxim_main_content}} where site_id = ' . $site_id);
     $tables = $this->getContentDumpTables(fx::collection($items));
     foreach ($tables as $t => $item_ids) {
         if ($t === 'floxim_main_content') {
             continue;
         }
         // export content table
         fx::db()->dump(array('tables' => array($t), 'where' => 'id IN (' . join(',', $item_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true));
     }
 }
예제 #7
0
 public function getResultPath()
 {
     $rel_path = $this->source_http_path;
     $folder_name = array();
     foreach ($this->config as $key => $value) {
         if ($value && !in_array($key, array('async', 'output'))) {
             $folder_name[] = $key . '-' . $value;
         }
     }
     $folder_name = join('.', $folder_name);
     $rel_path = $folder_name . '/' . $rel_path;
     $full_path = fx::path('@thumbs/' . $rel_path);
     if (!file_exists($full_path)) {
         if ($this->config['async']) {
             $target_dir = dirname($full_path);
             if (!file_exists($target_dir)) {
                 fx::files()->mkdir($target_dir);
             }
         } else {
             $this->process($full_path);
         }
     }
     $path = fx::path()->http($full_path);
     return $path;
 }
예제 #8
0
 public function addJsBundle($files, $params = array())
 {
     // for dev mode
     if (fx::config('dev.on')) {
         foreach ($files as $f) {
             $this->addJsFile($f);
         }
         return;
     }
     if (!isset($params['name'])) {
         $params['name'] = md5(join($files));
     }
     $params['name'] .= '.js.gz';
     $http_path = fx::path()->http('@files/asset_cache/' . $params['name']);
     $full_path = fx::path()->abs($http_path);
     $http_files = array();
     foreach ($files as $f) {
         if (!empty($f)) {
             $http_files[] = fx::path()->http($f);
         }
     }
     $this->all_js = array_merge($this->all_js, $http_files);
     if (!file_exists($full_path)) {
         $bundle_content = '';
         foreach ($files as $i => $f) {
             if (!preg_match("~^http://~i", $f)) {
                 $f = fx::path()->abs($f);
             }
             $file_content = file_get_contents($f);
             if (!preg_match("~\\.min~", $f)) {
                 $minified = \JSMin::minify($file_content);
                 $file_content = $minified;
             }
             $bundle_content .= $file_content . ";\n";
         }
         $plain_path = preg_replace("~\\.js\\.gz\$~", ".js", $full_path);
         fx::files()->writefile($plain_path, $bundle_content);
         $fh = gzopen($full_path, 'wb5');
         gzwrite($fh, $bundle_content);
         gzclose($fh);
     }
     if (!$this->acceptGzip()) {
         $http_path = preg_replace("~\\.js\\.gz\$~", ".js", $http_path);
     }
     $this->files_js[] = $http_path;
 }
예제 #9
0
파일: Debug.php 프로젝트: floxim/floxim
 public function dropAll()
 {
     $log_files = glob($this->getDir() . '/log*');
     $ifh = fx::files()->open($this->getIndexFileName(), 'w');
     fputs($ifh, '');
     fclose($ifh);
     $this->setCount(0);
     if (!$log_files) {
         return;
     }
     $own_file = fx::path()->abs($this->getFileName());
     foreach ($log_files as $lf) {
         if (fx::path()->abs($lf) != $own_file) {
             fx::files()->rm($lf);
         }
     }
 }