示例#1
0
文件: Sync.php 项目: vgrish/dvelum
 /**
  * (non-PHPdoc)
  * @see Bgtask_Abstract::run()
  */
 public function run()
 {
     $lang = Lang::lang();
     $this->setTotalCount(4);
     $config = Registry::get('main', 'config');
     $deployCfg = Config::factory(Config::File_Array, $config->get('configs') . 'deploy.php');
     $delimiter = $config->get('urlDelimiter');
     $url = 'http://' . str_replace(array('http://', $delimiter . $delimiter, $config->get('urlExtension')), array('', $delimiter, ''), $this->_config['url'] . $delimiter . 'deploy' . $delimiter . 'syncfiles');
     $dataSend = array('key' => Utils::hash($this->_config['key']));
     $curl = curl_init();
     $this->log('Connecting to ' . $url . '...');
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_VERBOSE, 0);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $dataSend);
     curl_setopt($curl, CURLOPT_TIMEOUT, 3600);
     $result = curl_exec($curl);
     $this->_nextStep();
     if ($result === false) {
         $this->error(curl_error($curl));
     }
     $data = json_decode($result, true);
     if (empty($data) || !is_array($data)) {
         $this->error('Empty response from server');
     }
     if (!$data['success']) {
         $this->error('Remote server error. ' . $data['msg']);
     }
     if (!isset($data['data']['files'])) {
         $this->error('Invalid result');
     }
     $data = $data['data'];
     $serverDir = $deployCfg->get('datadir') . $this->_config['id'] . '/';
     if (!file_exists($serverDir) && !mkdir($serverDir)) {
         $this->error($lang->CANT_WRITE_FS . '(' . $serverDir . ')');
     }
     $this->_nextStep();
     if (!Utils::exportArray($serverDir . 'map.php', $data['files'])) {
         $this->error($lang->CANT_WRITE_FS . '(' . $serverDir . 'map.php' . ')');
     }
     $this->_nextStep();
     if (!@file_put_contents($serverDir . 'lastfsupdate', date('Y-m-d H:i:s'))) {
         $this->error($lang->CANT_WRITE_FS . '(' . $serverDir . 'lastfsupdate' . ')');
     }
     $this->_nextStep();
     $this->finish();
 }
示例#2
0
文件: Deploy.php 项目: vgrish/dvelum
 /**
  * Create FS map using php functions
  * @return mixed bulean|array
  */
 protected function _fsmapByPhp($toFile = false)
 {
     ini_set('max_execution_time', 3600);
     $deployCfg = Config::factory(Config::File_Array, $this->_appConfig['configs'] . 'deploy.php');
     $list = File::scanFiles('.', array(), $recursive = true);
     $ignore = $deployCfg->get('ignore');
     $result = array();
     foreach ($list as $k => $lfile) {
         if (is_dir($lfile)) {
             continue;
         }
         $good = true;
         $lfile = str_replace('\\', '/', $lfile);
         $fName = $lfile;
         if (is_dir($fName)) {
             $fName .= '/';
         }
         foreach ($ignore as $string) {
             if (strpos($fName, $string) !== false) {
                 $good = false;
                 break;
             }
         }
         if ($good) {
             $nameHash = md5($lfile);
             $fileHash = md5_file($lfile);
             $result[$nameHash] = array('file' => $lfile, 'md5' => $fileHash);
         }
     }
     if ($toFile !== false) {
         return Utils::exportArray($toFile, $result);
     } else {
         return $result;
     }
 }
示例#3
0
文件: Manager.php 项目: vgrish/dvelum
 /**
  * Create sub dicionary
  * @throws Exception
  * @param string $name
  */
 public function createDictionary($name)
 {
     $filePath = $this->_langsPath . $this->getIndexName($name);
     if (!Utils::exportArray($filePath, array())) {
         throw new Exception($this->_lang->get('CANT_WRITE_FS') . ' ' . $filePath);
     }
     $langs = $this->getLangs(true);
     foreach ($langs as $lang) {
         $filePath = $this->_langsPath . $lang . '/' . $name . '.php';
         if (!Utils::exportArray($filePath, array())) {
             throw new Exception($this->_lang->get('CANT_WRITE_FS') . ' ' . $filePath);
         }
     }
 }