예제 #1
0
 public function actionIndex()
 {
     $src = DOCGEN_PATH . '/swagger-ui/';
     $dst = Yii::getAlias('@app') . '/web/apidoc/';
     FileHelper::copyDirectory($src, $dst);
     return Controller::EXIT_CODE_NORMAL;
 }
예제 #2
0
 /**
  * (non-PHPdoc)
  * EXTRA: 
  * @see \yii\web\AssetManager::publishDirectory()
  * 
  *  [const-dir] contain directory name or empty if copy current asset directly to base assets' dir 
  */
 public function publishDirectory($src, $options)
 {
     throw new \yii\base\Exception('works but block support until it will be required. skip testing purpose');
     // default behavior with hashed dir
     if (!isset($options['const-dir'])) {
         return parent::publishDirectory($src, $options);
     }
     //
     // my custom : don't generate random dir, instead, use custom if set
     //
     $dstDir = $this->basePath . (!empty($options['const-dir']) ? '/' . $options['const-dir'] : '');
     //dont copy if already was copied
     // TODO: add datetime checks
     if (file_exists($dstDir)) {
         return [$dstDir, $this->baseUrl];
     }
     // A. copy only subdirs if set
     if (!empty($options['sub-dirs']) && is_array($options['sub-dirs'])) {
         foreach ($options['sub-dirs'] as $subdir) {
             if (is_dir($src . '/' . $subdir)) {
                 FileHelper::copyDirectory($src . '/' . $subdir, $dstDir . '/' . $subdir, ['dirMode' => $this->dirMode, 'fileMode' => $this->fileMode, 'beforeCopy' => @$options['beforeCopy'], 'afterCopy' => @$options['afterCopy'], 'forceCopy' => @$options['forceCopy']]);
             }
             //TODO: else write error log
         }
     } else {
         //copy whole dir
         FileHelper::copyDirectory($src, $dstDir, ['dirMode' => $this->dirMode, 'fileMode' => $this->fileMode, 'beforeCopy' => @$options['beforeCopy'], 'afterCopy' => @$options['afterCopy'], 'forceCopy' => @$options['forceCopy']]);
     }
     return [$dstDir, $this->baseUrl];
 }
예제 #3
0
 /**
  * Renders API documentation files
  * @param array $sourceDirs
  * @param string $targetDir
  * @return int
  */
 public function actionIndex(array $sourceDirs, $targetDir)
 {
     $renderer = $this->findRenderer($this->template);
     $targetDir = $this->normalizeTargetDir($targetDir);
     if ($targetDir === false || $renderer === false) {
         return 1;
     }
     $renderer->guideUrl = './';
     // setup reference to apidoc
     if ($this->apiDocs !== null) {
         $renderer->apiUrl = $this->apiDocs;
         $renderer->apiContext = $this->loadContext($this->apiDocs);
     } elseif (file_exists($targetDir . '/cache/apidoc.data')) {
         $renderer->apiUrl = './';
         $renderer->apiContext = $this->loadContext($targetDir);
     } else {
         $renderer->apiContext = new Context();
     }
     $this->updateContext($renderer->apiContext);
     // search for files to process
     if (($files = $this->searchFiles($sourceDirs)) === false) {
         return 1;
     }
     $renderer->controller = $this;
     $renderer->render($files, $targetDir);
     $this->stdout('Publishing images...');
     foreach ($sourceDirs as $source) {
         FileHelper::copyDirectory(rtrim($source, '/\\') . '/images', $targetDir . '/images');
     }
     $this->stdout('done.' . PHP_EOL, Console::FG_GREEN);
 }
예제 #4
0
 public function registerAssetFiles($view)
 {
     parent::registerAssetFiles($view);
     // Копируем картинки
     $manager = $view->getAssetManager();
     $dst = $manager->getAssetUrl($this, 'bootstrap/css/images');
     $src = __DIR__ . '/assets/bootstrap/css/images';
     FileHelper::copyDirectory($src, $dst);
 }
 public function actionIndex($environment)
 {
     $directory = \Yii::$app->basePath . '/environments/' . $environment;
     if (file_exists($directory)) {
         FileHelper::copyDirectory($directory, \Yii::$app->basePath);
         echo Console::renderColoredString('%g' . \Yii::t('app.console', 'Окружение успешно сменено на {env}', ['env' => $environment]), true);
         echo Console::renderColoredString("%n\n");
     } else {
         throw new Exception(\Yii::t('app.console', 'Указанного окружения не существует'));
     }
 }
예제 #6
0
 /**
  * @inheritdoc
  */
 public function run(&$cmdParams, &$params)
 {
     $res = true;
     $taskRunner = $this->taskRunner;
     $toBeCopied = [];
     $srcDirList = !empty($cmdParams[0]) ? $cmdParams[0] : [];
     $destDir = !empty($cmdParams[1]) ? $taskRunner->parsePath($cmdParams[1]) : '';
     $srcBaseDir = !empty($cmdParams[2]) ? $taskRunner->parsePath($cmdParams[2]) : '';
     $options = !empty($cmdParams[3]) ? $cmdParams[3] : [];
     if (empty($srcDirList) || empty($destDir)) {
         throw new Exception('copyDir: Base and destination cannot be empty');
     }
     if (!empty($srcBaseDir) && !is_dir($srcBaseDir) || file_exists($destDir) && !is_dir($destDir)) {
         throw new Exception('copyDir: Base and destination have to be directories');
     }
     // if srcDirList is specified but it is a string, we convert it to an array
     if (!empty($srcDirList) && is_string($srcDirList)) {
         $srcDirList = explode(',', $srcDirList);
     }
     foreach ($srcDirList as $dirPath) {
         $parsedPath = $taskRunner->parseStringAliases(trim($dirPath));
         if (!empty($srcBaseDir)) {
             $toBeCopied[$parsedPath] = $srcBaseDir . DIRECTORY_SEPARATOR . $parsedPath;
         } else {
             $toBeCopied[] = $parsedPath;
         }
     }
     foreach ($toBeCopied as $srcRelPath => $srcDirPath) {
         if (is_dir($srcDirPath)) {
             /* *
              * if the destination directory already exists or if we are
              * copying more than one directory, we copy the source directory inside
              * of the destination directory instead of replacing the destination
              * directory with it
              * */
             $destDirPath = $destDir;
             if (is_dir($destDirPath) || count($toBeCopied) > 1) {
                 $srcRelPath = !empty($srcBaseDir) ? $srcRelPath : basename($srcDirPath);
                 $destDirPath = $destDir . DIRECTORY_SEPARATOR . $srcRelPath;
             }
             $this->controller->stdout("Copy directory: \n  " . $srcDirPath . " to \n  " . $destDirPath);
             if (!$this->controller->dryRun) {
                 FileHelper::copyDirectory($srcDirPath, $destDirPath, $options);
             } else {
                 $this->controller->stdout(' [dry run]', Console::FG_YELLOW);
             }
             $this->controller->stdout("\n");
         } else {
             $this->controller->stderr("{$srcDirPath} is not a directory!\n", Console::FG_RED);
         }
     }
     return $res;
 }
예제 #7
0
 /**
  * Renders API documentation files
  * @param array $sourceDirs
  * @param string $targetDir
  * @return int
  */
 public function actionIndex(array $sourceDirs, $targetDir)
 {
     $renderer = $this->findRenderer($this->template);
     $targetDir = $this->normalizeTargetDir($targetDir);
     if ($targetDir === false || $renderer === false) {
         return 1;
     }
     if ($this->pageTitle !== null) {
         $renderer->pageTitle = $this->pageTitle;
     }
     if ($renderer->guideUrl === null) {
         $renderer->guideUrl = './';
     }
     $renderer->guidePrefix = $this->guidePrefix;
     // setup reference to apidoc
     if ($this->apiDocs !== null) {
         $path = $this->apiDocs;
         if ($renderer->apiUrl === null) {
             $renderer->apiUrl = $path;
         }
         // use relative paths relative to targetDir
         if (strncmp($path, '.', 1) === 0) {
             $renderer->apiContext = $this->loadContext("{$targetDir}/{$path}");
         } else {
             $renderer->apiContext = $this->loadContext($path);
         }
     } elseif (file_exists($targetDir . '/cache/apidoc.data')) {
         if ($renderer->apiUrl === null) {
             $renderer->apiUrl = './';
         }
         $renderer->apiContext = $this->loadContext($targetDir);
     } else {
         $renderer->apiContext = new Context();
     }
     $this->updateContext($renderer->apiContext);
     // search for files to process
     if (($files = $this->searchFiles($sourceDirs)) === false) {
         return 1;
     }
     $renderer->controller = $this;
     $renderer->render($files, $targetDir);
     $this->stdout('Publishing images...');
     foreach ($sourceDirs as $source) {
         $imageDir = rtrim($source, '/\\') . '/images';
         if (file_exists($imageDir)) {
             FileHelper::copyDirectory($imageDir, $targetDir . '/images');
         }
     }
     $this->stdout('done.' . PHP_EOL, Console::FG_GREEN);
 }
예제 #8
0
파일: Shell.php 프로젝트: giovdk21/deployii
 /**
  * Initialise the home directory:
  * - if not present, create it copying the content from the home-dist directory
  * - if present check if the home directory is up to date with the latest DeploYii version
  */
 public static function initHomeDir()
 {
     if (!self::$_initialised) {
         $home = self::getHomeDir();
         if (!is_dir($home)) {
             FileHelper::copyDirectory(__DIR__ . '/../home-dist', $home);
             @unlink($home . '/README.md');
             VersionManager::updateHomeVersion();
         } else {
             $homeVersion = VersionManager::getHomeVersion();
             VersionManager::checkHomeVersion($homeVersion);
         }
     }
     self::$_initialised = true;
 }
예제 #9
0
 /**
  * Copies original module files to destination folder.
  * @return bool
  * @throws ErrorException
  */
 private function copy()
 {
     $source = Yii::getAlias($this->source);
     if (!file_exists($source) || !is_dir($source)) {
         throw new ErrorException("Source directory {$this->source} not found");
     }
     $destination = Yii::getAlias($this->destination);
     if (!$this->replace && is_dir($destination)) {
         // if replace is disabled we will skip existing files
         $this->keepFiles = FileHelper::findFiles($destination);
     }
     FileHelper::copyDirectory($source, $destination, ['except' => ['.git/'], 'fileMode' => 0775, 'beforeCopy' => function ($from, $to) {
         return $this->replace || !file_exists($to) || !is_file($to);
     }]);
     return true;
 }
예제 #10
0
 /**
  * @throws \Exception
  * @throws \yii\base\ErrorException
  * @throws \yii\base\Exception
  */
 protected function _copyMigrations()
 {
     $this->stdout("Copy the migration files in a single directory\n", Console::FG_YELLOW);
     $tmpMigrateDir = \Yii::getAlias($this->_runtimeMigrationPath);
     FileHelper::removeDirectory($tmpMigrateDir);
     FileHelper::createDirectory($tmpMigrateDir);
     if (!is_dir($tmpMigrateDir)) {
         $this->stdout("Could not create a temporary directory migration\n");
         die;
     }
     $this->stdout("\tCreated a directory migration\n");
     if ($dirs = $this->_findMigrationDirs()) {
         foreach ($dirs as $path) {
             FileHelper::copyDirectory($path, $tmpMigrateDir);
         }
     }
     $this->stdout("\tThe copied files modules migrations\n");
     $appMigrateDir = \Yii::getAlias("@console/migrations");
     if (is_dir($appMigrateDir)) {
         FileHelper::copyDirectory($appMigrateDir, $tmpMigrateDir);
     }
     $this->stdout("\tThe copied files app migrations\n\n");
 }
 /**
  * Generates the Definitive Guide for the specified version of Yii.
  * @param string $version version number, such as 1.1, 2.0
  * @return integer exit status
  */
 public function actionGenerate($version)
 {
     $versions = Yii::$app->params['guide.versions'];
     if (!isset($versions[$version])) {
         $this->stderr("Unknown version {$version}. Valid versions are " . implode(', ', array_keys($versions)) . "\n\n", Console::FG_RED);
         return 1;
     }
     $languages = $versions[$version];
     $targetPath = Yii::getAlias('@app/data');
     $sourcePath = Yii::getAlias('@app/data');
     try {
         // prepare elasticsearch index
         SearchGuideSection::setMappings();
         sleep(1);
     } catch (\Exception $e) {
         if (YII_DEBUG) {
             $this->stdout("!!! FAILED to prepare elasticsearch index !!! Search will not be available.\n", Console::FG_RED, Console::BOLD);
             $this->stdout((string) $e . "\n\n");
         } else {
             throw $e;
         }
     }
     if ($version[0] === '2') {
         foreach ($languages as $language => $name) {
             $source = "{$sourcePath}/yii-{$version}/docs/guide";
             if ($language !== 'en') {
                 if (strpos($language, '-') !== false) {
                     list($lang, $locale) = explode('-', $language);
                     $source .= "-{$lang}" . (empty($locale) ? '' : '-' . strtoupper($locale));
                 } else {
                     $source .= "-{$language}";
                 }
             }
             $target = "{$targetPath}/guide-{$version}/{$language}";
             $pdfTarget = "{$targetPath}/guide-{$version}/{$language}/pdf";
             $this->version = $version;
             $this->language = $language;
             $this->apiDocs = Yii::getAlias("@app/data/api-{$version}");
             $this->stdout("Start generating guide {$version} in {$name}...\n", Console::FG_CYAN);
             $this->template = 'bootstrap';
             $this->actionIndex([$source], $target);
             $this->generateIndex($source, $target);
             $this->stdout("Finished guide {$version} in {$name}.\n\n", Console::FG_CYAN);
             // set LaTeX language
             $languageMap = Yii::$app->params['guide-pdf.languages'];
             if (isset($languageMap[$language])) {
                 $this->stdout("Start generating guide {$version} PDF in {$name}...\n", Console::FG_CYAN);
                 $this->template = 'pdf';
                 $this->actionIndex([$source], $pdfTarget);
                 $this->stdout('Generating PDF with pdflatex...');
                 file_put_contents("{$pdfTarget}/main.tex", str_replace('british', $languageMap[$language], file_get_contents("{$pdfTarget}/main.tex")));
                 exec('cd ' . escapeshellarg($pdfTarget) . ' && make pdf', $output, $ret);
                 if ($ret === 0) {
                     $this->stdout("\nFinished guide {$version} PDF in {$name}.\n\n", Console::FG_CYAN);
                 } else {
                     $this->stdout("\n" . implode("\n", $output) . "\n");
                     $this->stdout("Guide {$version} PDF failed, make exited with status {$ret}.\n\n", Console::FG_RED);
                 }
             } else {
                 $this->stdout("Guide PDF is not available for {$name}.\n\n", Console::FG_CYAN);
             }
         }
     }
     if ($version[0] === '1') {
         foreach ($languages as $language => $name) {
             $unnormalizedLanguage = strtolower(str_replace('-', '_', $language));
             $source = "{$sourcePath}/yii-{$version}/docs/guide";
             $target = "{$targetPath}/guide-{$version}/{$language}";
             //                $pdfTarget = "$targetPath/guide-$version/$language/pdf"; TODO
             $this->version = $version;
             $this->language = $language;
             FileHelper::createDirectory($target);
             $renderer = new Yii1GuideRenderer(['basePath' => $source, 'targetPath' => $target]);
             $this->stdout("Start generating guide {$version} in {$name}...\n", Console::FG_CYAN);
             $renderer->renderGuide($version, $unnormalizedLanguage);
             $this->generateIndexYii1($source, $target, $version, $unnormalizedLanguage);
             FileHelper::copyDirectory("{$source}/images", "{$target}/images");
             $this->stdout("Finished guide {$version} in {$name}.\n\n", Console::FG_CYAN);
         }
         // generate blog tutorial
         if (isset(Yii::$app->params['blogtut.versions'][$version])) {
             foreach (Yii::$app->params['blogtut.versions'][$version] as $language => $name) {
                 $unnormalizedLanguage = strtolower(str_replace('-', '_', $language));
                 $source = "{$sourcePath}/yii-{$version}/docs/blog";
                 $target = "{$targetPath}/blogtut-{$version}/{$language}";
                 //                $pdfTarget = "$targetPath/guide-$version/$language/pdf"; TODO
                 $this->version = $version;
                 $this->language = $language;
                 FileHelper::createDirectory($target);
                 $renderer = new Yii1GuideRenderer(['basePath' => $source, 'targetPath' => $target]);
                 $this->stdout("Start generating blog tutorial {$version} in {$name}...\n", Console::FG_CYAN);
                 $renderer->renderBlog($version, $unnormalizedLanguage);
                 $this->generateIndexYii1($source, $target, $version, $unnormalizedLanguage, 'blog');
                 FileHelper::copyDirectory("{$source}/images", "{$target}/images");
                 $this->stdout("Finished blog tutorial {$version} in {$name}.\n\n", Console::FG_CYAN);
             }
         }
     }
     return 0;
 }
예제 #12
0
 public function actionCopy($id)
 {
     $module = Module::findOne($id);
     $formModel = new CopyModuleForm();
     if ($module === null) {
         $this->flash('error', 'Not found');
         return $this->redirect('/populac/modules');
     }
     if ($formModel->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($formModel);
         } else {
             $reflector = new \ReflectionClass($module->class);
             $oldModuleFolder = dirname($reflector->getFileName());
             $oldNameSpace = $reflector->getNamespaceName();
             $oldModuleClass = $reflector->getShortName();
             $newModulesFolder = Yii::getAlias('@app') . DIRECTORY_SEPARATOR . 'modules';
             $newModuleFolder = Yii::getAlias('@app') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $formModel->name;
             //$newNameSpace = 'app\modules\\'.$formModel->name;
             $newNameSpace = 'backend\\modules\\' . $formModel->name;
             $newModuleClass = ucfirst($formModel->name) . 'Module';
             if (!FileHelper::createDirectory($newModulesFolder, 0755)) {
                 $this->flash('error', 'Cannot create `' . $newModulesFolder . '`. Please check write permissions.');
                 return $this->refresh();
             }
             if (file_exists($newModuleFolder)) {
                 $this->flash('error', 'New module folder `' . $newModulesFolder . '` already exists.');
                 return $this->refresh();
             }
             //Copying module folder
             try {
                 FileHelper::copyDirectory($oldModuleFolder, $newModuleFolder);
             } catch (\Exception $e) {
                 $this->flash('error', 'Cannot copy `' . $oldModuleFolder . '` to `' . $newModuleFolder . '`. Please check write permissions.');
                 return $this->refresh();
             }
             //Renaming module file name
             $newModuleFile = $newModuleFolder . DIRECTORY_SEPARATOR . $newModuleClass . '.php';
             $oldModuleFile = $newModuleFolder . DIRECTORY_SEPARATOR . $reflector->getShortName() . '.php';
             if (!rename($oldModuleFile, $newModuleFile)) {
                 $this->flash('error', 'Cannot rename `' . $newModulesFolder . '`.');
                 return $this->refresh();
             }
             //Renaming module class name
             $moduleFileContent = file_get_contents($newModuleFile);
             $moduleFileContent = str_replace($oldModuleClass, $newModuleClass, $moduleFileContent);
             $moduleFileContent = str_replace('@easyii', '@app', $moduleFileContent);
             $moduleFileContent = str_replace('/' . $module->name, '/' . $formModel->name, $moduleFileContent);
             file_put_contents($newModuleFile, $moduleFileContent);
             //Replacing namespace
             foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($newModuleFolder)) as $file => $object) {
                 if (!$object->isDir()) {
                     $fileContent = file_get_contents($file);
                     $fileContent = str_replace($oldNameSpace, $newNameSpace, $fileContent);
                     $fileContent = str_replace("Yii::t('easyii/" . $module->name, "Yii::t('easyii/" . $formModel->name, $fileContent);
                     $fileContent = str_replace("'" . $module->name . "'", "'" . $formModel->name . "'", $fileContent);
                     file_put_contents($file, $fileContent);
                 }
             }
             //Copying module tables
             foreach (glob($newModuleFolder . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . '*.php') as $modelFile) {
                 $baseName = basename($modelFile, '.php');
                 $modelClass = $newNameSpace . '\\models\\' . $baseName;
                 $oldTableName = $modelClass::tableName();
                 $newTableName = str_replace($module->name, $formModel->name, $oldTableName);
                 $newTableName = str_replace('easyii', 'app', $newTableName);
                 //Yii::info($oldTableName, 'oldtb');
                 //Yii::info($newTableName, 'newtb');
                 try {
                     //Drop new table if exists
                     //如果有用到表前缀必须 ".$newTableName." 这样写
                     //如果没有用到表前缀则必须改为 "DROP TABLE IF EXISTS `$newTableName`;" 的写法。
                     Yii::$app->db->createCommand("DROP TABLE IF EXISTS " . $newTableName . ";")->execute();
                     //Copy new table
                     Yii::$app->db->createCommand("CREATE TABLE " . $newTableName . " LIKE " . $oldTableName . ";")->execute();
                 } catch (\yii\db\Exception $e) {
                     $this->flash('error', 'Copy table error. ' . $e);
                     FileHelper::removeDirectory($newModuleFolder);
                     return $this->refresh();
                 }
                 file_put_contents($modelFile, str_replace($oldTableName, $newTableName, file_get_contents($modelFile)));
             }
             $newModule = new Module(['name' => $formModel->name, 'class' => $newNameSpace . '\\' . $newModuleClass, 'title' => $formModel->title, 'icon' => $module->icon, 'settings' => $module->settings, 'status' => Module::STATUS_ON]);
             if ($newModule->save()) {
                 $this->flash('success', 'New module created');
                 return $this->redirect(['/populac/modules/edit', 'id' => $newModule->primaryKey]);
             } else {
                 $this->flash('error', 'Module create error. ' . $newModule->formatErrors());
                 FileHelper::removeDirectory($newModuleFolder);
                 return $this->refresh();
             }
         }
     }
     return $this->render('copy', ['model' => $module, 'formModel' => $formModel]);
 }
예제 #13
0
 /**
  * 更新插件
  */
 public static function update($pluginid)
 {
     $data = array('status' => self::STATUS_ERROR, 'msg' => '未知错误');
     $updateDir = self::GetPluginPath($pluginid) . "/update/";
     $configRaw = self::GetPluginConfig($pluginid, false, $updateDir);
     $config = $configRaw['config'];
     if ($config) {
         //更新config
         $oldVersionRows = SystemConfig::Get(strtoupper("PLUGIN_{$pluginid}_VERSION"), null, "USER");
         $oldVersionRow = array_shift($oldVersionRows);
         $oldVersion = !empty($oldVersionRow) ? floatval($oldVersionRow['cfg_value']) : 0;
         $newVersion = floatval($config['version']);
         if ($newVersion > $oldVersion) {
             try {
                 //更新配置文件
                 $conffile = $updateDir . "config.php";
                 $destconffile = self::GetPluginPath($pluginid) . "/config.php";
                 if (is_file($conffile)) {
                     copy($conffile, $destconffile);
                 }
                 //更新lib和views
                 $libDir = $updateDir . "lib";
                 $viewsDir = $updateDir . "views";
                 if (is_dir($viewsDir)) {
                     FileHelper::copyDirectory($viewsDir, self::GetPluginPath($pluginid) . "/views");
                 }
                 if (is_dir($libDir)) {
                     FileHelper::copyDirectory($libDir, self::GetPluginPath($pluginid) . "/lib");
                 }
             } catch (ErrorException $e) {
                 return ['status' => self::STATUS_ERROR, 'msg' => "更新失败,没有权限移动升级文件,请修正权限"];
             }
             $data['status'] = self::STATUS_SUCCESS;
             $data['msg'] = "更新完成!";
             if (!$config['onlyupdatefiles']) {
                 //卸载 只删除数据库中菜单的配置
                 self::unsetup($pluginid);
                 //更新配置
                 $_data = self::setup($pluginid);
                 if (!$_data['status']) {
                     $data['msg'] .= ' ' . $_data['msg'];
                 }
             } else {
                 //更新数据库的插件版本号
                 if ($oldVersionRow) {
                     $id = isset($oldVersionRow['id']) ? $oldVersionRow['id'] : 0;
                     if ($id > 0) {
                         $params = $oldVersionRow;
                         $params['cfg_value'] = $newVersion;
                         SystemConfig::Update($id, $params);
                     }
                 }
             }
             //删除升级目录
             FileHelper::removeDirectory($updateDir);
         } else {
             $data['msg'] = '更新失败,版本号低于当前版本,禁止更新操作!';
         }
     } else {
         $data['msg'] = '更新失败,配置文件有误!';
     }
     return $data;
 }
예제 #14
0
 /**
  * @see https://github.com/yiisoft/yii2/issues/3393
  *
  * @depends testCopyDirectory
  * @depends testFindFiles
  */
 public function testCopyDirectoryExclude()
 {
     $srcDirName = 'test_src_dir';
     $textFiles = ['file1.txt' => 'text file 1 content', 'file2.txt' => 'text file 2 content'];
     $dataFiles = ['file1.dat' => 'data file 1 content', 'file2.dat' => 'data file 2 content'];
     $this->createFileStructure([$srcDirName => array_merge($textFiles, $dataFiles)]);
     $basePath = $this->testFilePath;
     $srcDirName = $basePath . DIRECTORY_SEPARATOR . $srcDirName;
     $dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_dst_dir';
     FileHelper::copyDirectory($srcDirName, $dstDirName, ['only' => ['*.dat']]);
     $this->assertFileExists($dstDirName, 'Destination directory does not exist!');
     $copiedFiles = FileHelper::findFiles($dstDirName);
     $this->assertCount(2, $copiedFiles, 'wrong files count copied');
     foreach ($dataFiles as $name => $content) {
         $fileName = $dstDirName . DIRECTORY_SEPARATOR . $name;
         $this->assertFileExists($fileName);
         $this->assertEquals($content, file_get_contents($fileName), 'Incorrect file content!');
     }
 }
예제 #15
0
 /**
  * @depends testCopyDirectory
  */
 public function testCopyDirectoryPermissions()
 {
     if (substr(PHP_OS, 0, 3) == 'WIN') {
         $this->markTestSkipped("Can't reliably test it on Windows because fileperms() always return 0777.");
     }
     $srcDirName = 'test_src_dir';
     $subDirName = 'test_sub_dir';
     $fileName = 'test_file.txt';
     $this->createFileStructure([$srcDirName => [$subDirName => [], $fileName => 'test file content']]);
     $basePath = $this->testFilePath;
     $srcDirName = $basePath . DIRECTORY_SEPARATOR . $srcDirName;
     $dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_dst_dir';
     $dirMode = 0755;
     $fileMode = 0755;
     $options = ['dirMode' => $dirMode, 'fileMode' => $fileMode];
     FileHelper::copyDirectory($srcDirName, $dstDirName, $options);
     $this->assertFileMode($dirMode, $dstDirName, 'Destination directory has wrong mode!');
     $this->assertFileMode($dirMode, $dstDirName . DIRECTORY_SEPARATOR . $subDirName, 'Copied sub directory has wrong mode!');
     $this->assertFileMode($fileMode, $dstDirName . DIRECTORY_SEPARATOR . $fileName, 'Copied file has wrong mode!');
 }
예제 #16
0
 public function copyTo($targetDir)
 {
     FileHelper::copyDirectory($this->path, $targetDir);
 }
예제 #17
0
 /**
  * 
  * @param string $src
  * @param string $dst
  */
 protected function copyDirectory($src, $dst)
 {
     if ($src === $dst || strpos($dst, $src) === 0) {
         foreach ($this->findDirs($src, $dst) as $dir => $src) {
             FileHelper::copyDirectory($src, $dst . '/' . $dir);
         }
     } else {
         FileHelper::copyDirectory($src, $dst);
     }
 }
예제 #18
0
    public function actionFillData($data = '')
    {
        if(!$data) {
            $data = 'all';
        }

        if($data == 'textblock' || $data == 'all') {
            /* TextBlock */
            Yii::$app->db->createCommand()
                ->batchInsert(TextBlock::tableName(), ['name', 'key', 'created_at', 'updated_at', 'created_by', 'updated_by'],
                    [
                        ['counters', '', time(), time(), 1, 1], // 1
                        ['socials', 'facebook', time(), time(), 1, 1], // 2
                        ['socials', 'twitter', time(), time(), 1, 1], // 3
                        ['socials', 'linkedin', time(), time(), 1, 1], // 4
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(TextBlockTranslation::tableName(), ['parent_id', 'locale', 'text'],
                    [
                        ['1', 'en-US', '<!-- GA counter-->'],
                        ['1', 'ru-RU', '<!-- GA counter-->'],

                        ['2', 'en-US', 'http://www.facebook.com'],
                        ['2', 'ru-RU', 'http://www.facebook.com'],

                        ['3', 'en-US', 'http://twitter.com'],
                        ['3', 'ru-RU', 'http://twitter.com'],

                        ['4', 'en-US', 'https://www.linkedin.com'],
                        ['4', 'ru-RU', 'https://www.linkedin.com'],
                    ])
                ->execute();
        }

        if($data == 'news' || $data == 'all') {
            /* News categories */
            Yii::$app->db->createCommand()
                ->batchInsert(NewsCategory::tableName(), ['status', 'parent_id', 'position', 'created_at', 'updated_at', 'created_by', 'updated_by'],
                    [
                        [NewsCategory::STATUS_ACTIVE, null, 1, time(), time(), 1, 1], // 1
                        [NewsCategory::STATUS_ACTIVE, null, 2, time(), time(), 1, 1], // 2
                        [NewsCategory::STATUS_ACTIVE, 1, 3, time(), time(), 1, 1], // 3
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(NewsCategoryTranslation::tableName(), ['parent_id', 'locale', 'slug', 'title'],
                    [
                        ['1', 'en-US', 'cat-1', 'Category 1'],
                        ['1', 'ru-RU', 'cat-1-ru', 'Category 1 Ru'],

                        ['2', 'en-US', 'cat-2', 'Category 2'],
                        ['2', 'ru-RU', 'cat-2-ru', 'Category 2 Ru'],

                        ['3', 'en-US', 'cat-3', 'Category 3'],
                        ['3', 'ru-RU', 'cat-3-ru', 'Category 3 Ru'],
                    ])
                ->execute();

            /* News tags */
            Yii::$app->db->createCommand()
                ->batchInsert(NewsTag::tableName(), ['frequency'],
                    [
                        ['1'], // 1
                        ['1'], // 2
                        ['1'], // 3
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(NewsTagTranslation::tableName(), ['parent_id', 'locale', 'name'],
                    [
                        ['1', 'en-US', 'Tag 1'],
                        ['1', 'ru-RU', 'Tag 1 Ru'],

                        ['2', 'en-US', 'Tag 2'],
                        ['2', 'ru-RU', 'Tag 2 Ru'],

                        ['3', 'en-US', 'Tag 3'],
                        ['3', 'ru-RU', 'Tag 3 Ru'],
                    ])
                ->execute();

            /* News */
            Yii::$app->db->createCommand()
                ->batchInsert(News::tableName(), ['date', 'category_id', 'status', 'image', 'created_at', 'updated_at', 'created_by', 'updated_by'],
                    [
                        [time() - 2, '1', News::STATUS_ACTIVE, '1.jpg', time(), time(), 1, 1], // 1
                        [time() - 1, '1', News::STATUS_ACTIVE, '2.jpg', time(), time(), 1, 1], // 2
                        [time(), '1', News::STATUS_ACTIVE, '3.jpg', time(), time(), 1, 1], // 3
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(NewsTranslation::tableName(),
                    [
                        'parent_id', 'locale', 'slug',
                        'title', 'description', 'content',
                        'meta_title', 'meta_keywords', 'meta_description',
                        'image_description', 'redirect'
                    ],
                    [
                        ['1', 'en-US', 'news-1', 'News #1', 'Description #1', 'Content #1', 'Meta Title #1', 'Meta Keywords #1', 'Meta Description #1', 'Image Description #1', ''],
                        ['1', 'ru-RU', 'news-1-ru', 'News #1 Ru', 'Description #1 Ru', 'Content #1 Ru', 'Meta Title #1 Ru', 'Meta Keywords #1 Ru', 'Meta Description #1 Ru', 'Image Description #1 Ru', ''],

                        ['2', 'en-US', 'news-2', 'News #2 (with redirect)', 'Description #2', 'Content #2', 'Meta Title #2', 'Meta Keywords #2', 'Meta Description #2', 'Image Description #2', 'http://www.google.com'],
                        ['2', 'ru-RU', 'news-2-ru', 'News #2 Ru (with redirect)', 'Description #2 Ru', 'Content #2 Ru', 'Meta Title #2 Ru', 'Meta Keywords #2 Ru', 'Meta Description #2 Ru', 'Image Description #2 Ru', 'http://www.google.com'],

                        ['3', 'en-US', 'news-3', 'News #3', 'Description #3', 'Content #3', 'Meta Title #3', 'Meta Keywords #3', 'Meta Description #3', 'Image Description #3', ''],
                        ['3', 'ru-RU', 'news-3-ru', 'News #3 Ru', 'Description #3 Ru', 'Content #3 Ru', 'Meta Title #3 Ru', 'Meta Keywords #3 Ru', 'Meta Description #3 Ru', 'Image Description #3 Ru', ''],
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert('{{%news_news_category}}', ['news_id', 'category_id'],
                    [
                        [1, 1], // 1
                        [1, 2], // 2
                        [1, 3], // 3
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert('{{%news_news_tags}}', ['news_id', 'tag_id'],
                    [
                        [1, 1], // 1
                        [2, 2], // 2
                        [3, 3], // 3
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(NewsGallery::tableName(), ['parent_id', 'position', 'image'],
                    [
                        [1, '1', '1.jpg'], // 1
                        [1, '2', '2.jpg'], // 2
                        [1, '3', '3.jpg'], // 3
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(NewsGalleryTranslation::tableName(), ['parent_id', 'locale', 'image_text'],
                    [
                        ['1', 'en-US', 'Image #1'],
                        ['1', 'ru-RU', 'Image #1 Ru'],

                        ['2', 'en-US', 'Image #2'],
                        ['2', 'ru-RU', 'Image #2 Ru'],

                        ['3', 'en-US', 'Image #3'],
                        ['3', 'ru-RU', 'Image #3 Ru'],
                    ])
                ->execute();

            FileHelper::copyDirectory(Yii::getAlias('@frontend/web/install/uploads/news'), Yii::getAlias('@frontend/web/uploads/news'));
            FileHelper::copyDirectory(Yii::getAlias('@frontend/web/install/uploads/news_gallery'), Yii::getAlias('@frontend/web/uploads/news_gallery'));
        }


        if($data == 'banner' || $data == 'all') {
            /* Banner */
            Yii::$app->db->createCommand()
                ->batchInsert(BannerPlace::tableName(), ['title'],
                    [
                        ['First place'], // 1
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(Banner::tableName(),
                    [
                        'locale', 'place_id', 'title', 'image', 'link', 'new_wnd',
                        'status', 'priority', 'created_at', 'updated_at', 'created_by', 'updated_by'
                    ],
                    [
                        [
                            'en-US', '1', 'First banner', '1.jpg', 'http://www.google.com', '1',
                            Banner::STATUS_ACTIVE, 1, time(), time(), 1, 1
                        ], // 1
                    ])
                ->execute();

            FileHelper::copyDirectory(Yii::getAlias('@frontend/web/install/uploads/banner'), Yii::getAlias('@frontend/web/uploads/banner'));
        }


        if($data == 'vote' || $data == 'all') {
            /* Vote */
            Yii::$app->db->createCommand()
                ->batchInsert(Vote::tableName(), ['status', 'type', 'created_at', 'updated_at', 'created_by', 'updated_by'],
                    [
                        [Vote::STATUS_ACTIVE, Vote::TYPE_SINGLE, time(), time(), 1, 1], // 1
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(VoteTranslation::tableName(), ['parent_id', 'locale', 'title'],
                    [
                        ['1', 'en-US', 'Vote #1'],
                        ['1', 'ru-RU', 'Vote #1 Ru'],
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(VoteOption::tableName(), ['parent_id', 'position'],
                    [
                        [1, 1], // 1
                        [1, 2], // 1
                        [1, 3], // 1
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(VoteOptionTranslation::tableName(), ['parent_id', 'locale', 'title'],
                    [
                        ['1', 'en-US', 'Option #1'],
                        ['1', 'ru-RU', 'Option #1 Ru'],

                        ['2', 'en-US', 'Option #2'],
                        ['2', 'ru-RU', 'Option #2 Ru'],

                        ['3', 'en-US', 'Option #3'],
                        ['3', 'ru-RU', 'Option #3 Ru'],
                    ])
                ->execute();
        }


        if($data == 'menu' || $data == 'all') {
            /* Menu */
            Yii::$app->db->createCommand()
                ->batchInsert(Menu::tableName(), ['status', 'parent_id', 'position', 'created_at', 'updated_at', 'created_by', 'updated_by'],
                    [
                        [Menu::STATUS_ACTIVE, null, 1, time(), time(), 1, 1], // 1
                        [Menu::STATUS_ACTIVE, null, 2, time(), time(), 1, 1], // 2
                        [Menu::STATUS_ACTIVE, 1, 1, time(), time(), 1, 1], // 3
                        [Menu::STATUS_ACTIVE, 1, 2, time(), time(), 1, 1], // 4
                        [Menu::STATUS_ACTIVE, 1, 3, time(), time(), 1, 1], // 5
                        [Menu::STATUS_ACTIVE, 5, 1, time(), time(), 1, 1], // 6
                        [Menu::STATUS_ACTIVE, 2, 1, time(), time(), 1, 1], // 7
                        [Menu::STATUS_ACTIVE, 2, 2, time(), time(), 1, 1], // 8
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(MenuTranslation::tableName(), ['parent_id', 'locale', 'title', 'link'],
                    [
                        ['1', 'en-US', 'Main menu', ''],
                        ['1', 'ru-RU', 'Main menu Ru', ''],

                        ['2', 'en-US', 'Bottom menu', ''],
                        ['2', 'ru-RU', 'Bottom menu Ru', ''],

                        ['3', 'en-US', 'Home', '/'],
                        ['3', 'ru-RU', 'Home Ru', '/'],

                        ['4', 'en-US', 'Contact', '/site/contact'],
                        ['4', 'ru-RU', 'Contact Ru', '/site/contact'],

                        ['5', 'en-US', 'News', '/news'],
                        ['5', 'ru-RU', 'News Ru', '/news'],

                        ['6', 'en-US', 'Category 1', '/news/category/cat-1'],
                        ['6', 'ru-RU', 'Category 1 Ru', '/news/category/cat-1'],

                        ['7', 'en-US', 'Contact', '/site/contact'],
                        ['7', 'ru-RU', 'Contact Ru', '/site/contact'],

                        ['8', 'en-US', 'About us', '/page/about'],
                        ['8', 'ru-RU', 'About us Ru', '/page/about'],
                    ])
                ->execute();

        }


        if($data == 'page' || $data == 'all') {
            /* Page */
            Yii::$app->db->createCommand()
                ->batchInsert(Page::tableName(), ['status', 'created_at', 'updated_at', 'created_by', 'updated_by'],
                    [
                        [Page::STATUS_ACTIVE, time(), time(), 1, 1], // 1
                        [Page::STATUS_ACTIVE, time(), time(), 1, 1], // 2
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(PageTranslation::tableName(), ['parent_id', 'locale', 'slug', 'title', 'description', 'content', 'meta_title', 'meta_keywords', 'meta_description'],
                    [
                        ['1', 'en-US', 'main-page', 'Main page text title', 'Main page text description', 'Main page text contents', 'Main page text Meta title', 'Main page text Meta keywords', 'Main page text Meta description'],
                        ['1', 'ru-RU', 'main-page-ru', 'Main page text title Ru', 'Main page text description Ru', 'Main page text contents Ru', 'Main page text Meta title Ru', 'Main page text Meta keywords Ru', 'Main page text Meta description Ru'],

                        ['2', 'en-US', 'about', 'About', 'About description', 'About text', 'About meta title', 'About meta keywords', 'About meta description'],
                        ['2', 'ru-RU', 'about-ru', 'About Ru', 'About description Ru', 'About text Ru', 'About meta title Ru', 'About meta keywords Ru', 'About meta description Ru'],
                    ])
                ->execute();

        }


        if($data == 'slider' || $data == 'all') {
            /* Slider */
            Yii::$app->db->createCommand()
                ->batchInsert(Slider::tableName(), ['title'],
                    [
                        ['Main slider'], // 1
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(Slide::tableName(), ['slider_id', 'image', 'status', 'position', 'created_at', 'updated_at', 'created_by', 'updated_by'],
                    [
                        [1, '1.jpg', Slide::STATUS_ACTIVE, 1, time(), time(), 1, 1], // 1
                        [1, '2.jpg', Slide::STATUS_ACTIVE, 2, time(), time(), 1, 1], // 2
                        [1, '3.jpg', Slide::STATUS_ACTIVE, 3, time(), time(), 1, 1], // 3
                    ])
                ->execute();

            Yii::$app->db->createCommand()
                ->batchInsert(SlideTranslation::tableName(), ['parent_id', 'locale', 'title', 'description', 'link'],
                    [
                        ['1', 'en-US', 'Slide #1', 'Text for slide #1', 'http://www.twitter.com'],
                        ['1', 'ru-RU', 'Slide #1 Ru', 'Text for slide #1 Ru', 'http://www.twitter.com'],

                        ['2', 'en-US', 'Slide #2', 'Text for slide #2', 'http://www.facebook.com'],
                        ['2', 'ru-RU', 'Slide #2 Ru', 'Text for slide #2 Ru', 'http://www.facebook.com'],

                        ['3', 'en-US', 'Slide #3', '', ''],
                        ['3', 'ru-RU', 'Slide #3 Ru', '', ''],
                    ])
                ->execute();

            FileHelper::copyDirectory(Yii::getAlias('@frontend/web/install/uploads/slide'), Yii::getAlias('@frontend/web/uploads/slide'));
        }


        echo 'Done!';
        Yii::$app->cache->flush();
    }
예제 #19
0
 /**
  * For each version that is newer of the current DeploYii home version and that requires
  * changes, tells the user which changes need to be performed manually and if possible
  * updates it automatically.
  *
  * To update a file it is possible to amend it manually or to remove it; if the file is missing
  * it will be replaced with the original one from the home-dist folder.
  *
  * If some manual changes are required, it is possible to simply delete the VERSION file once
  * the changes have been applied.
  *
  * @param string $homeVersion The DeploYii home version
  *
  * @throws \yii\console\Exception if the home folder requires to be updated manually
  */
 public static function checkHomeVersion($homeVersion)
 {
     $changeLog = '';
     $requiredActions = '';
     $home = Shell::getHomeDir();
     $homeDist = __DIR__ . '/../home-dist';
     $changes = array_reverse(self::$_homeChangeList);
     foreach ($changes as $version => $list) {
         if (version_compare($version, $homeVersion, '>')) {
             // files to be manually updated by the user:
             if (isset($list['mod'])) {
                 foreach ($list['mod'] as $relFilePath => $logMessage) {
                     // If the destination file does not exists, add it from the dist folder
                     // instead of requesting the user to manually update it:
                     $destFile = $home . DIRECTORY_SEPARATOR . $relFilePath;
                     if (!file_exists($destFile)) {
                         $list['add'][$relFilePath] = $logMessage;
                         unset($list['mod'][$relFilePath]);
                     } else {
                         $requiredActions .= " - [{$version}] {$relFilePath}: {$logMessage}\n";
                     }
                 }
             }
             // files/directories to be added: (if no manual actions are required)
             if (empty($requiredActions) && isset($list['add'])) {
                 foreach ($list['add'] as $relPath => $logMessage) {
                     $srcPath = $homeDist . DIRECTORY_SEPARATOR . $relPath;
                     $destPath = $home . DIRECTORY_SEPARATOR . $relPath;
                     if (!is_dir($srcPath) && !file_exists($destPath) && file_exists($srcPath)) {
                         $changeLog .= " - [{$version}] Adding {$relPath} ({$logMessage})\n";
                         copy($srcPath, $destPath);
                     } elseif (is_dir($srcPath) && !is_dir($destPath)) {
                         $changeLog .= " - [{$version}] Adding directory: {$relPath} ({$logMessage})\n";
                         FileHelper::copyDirectory($srcPath, $destPath);
                     } elseif (is_dir($srcPath) && is_dir($destPath)) {
                         $requiredActions .= " - [{$version}] {$relPath}: {$logMessage}\n";
                     }
                 }
             }
             // files/directories to be removed: (if no manual actions are required)
             if (empty($requiredActions) && isset($list['rem'])) {
                 foreach ($list['rem'] as $relPath => $logMessage) {
                     $destPath = $home . DIRECTORY_SEPARATOR . $relPath;
                     if (!is_dir($destPath) && file_exists($destPath)) {
                         $changeLog .= " - [{$version}] Removing {$relPath} ({$logMessage})\n";
                         unlink($destPath);
                     } elseif (is_dir($destPath)) {
                         $requiredActions .= " - [{$version}] {$relPath}: {$logMessage}\n";
                     }
                 }
             }
         }
     }
     if (!empty($requiredActions)) {
         Log::throwException("Your DeploYii home folder needs to be manually updated to " . DEPLOYII_VERSION . ":\n" . $requiredActions . "When done delete the VERSION file and run DeploYii again.\n");
     } elseif (!empty($changeLog)) {
         self::updateHomeVersion();
         $message = "Your DeploYii home folder has been updated to: " . DEPLOYII_VERSION . ":\n" . $changeLog;
         Log::logger()->addInfo($message);
         Console::stdout("---------------------------------------------------------------\n" . $message . "---------------------------------------------------------------\n");
         sleep(2);
     }
 }
예제 #20
0
 /**
  * Removes a module
  * 
  * @param strng $id the module id
  */
 public function removeModule($moduleId, $disableBeforeRemove = true)
 {
     $module = $this->getModule($moduleId);
     if ($module == null) {
         throw new Exception("Could not load module to remove!");
     }
     /**
      * Disable Module
      */
     if ($disableBeforeRemove && Yii::$app->hasModule($moduleId)) {
         $module->disable();
     }
     /**
      * Remove Folder
      */
     if ($this->createBackup) {
         $moduleBackupFolder = Yii::getAlias("@runtime/module_backups");
         if (!is_dir($moduleBackupFolder)) {
             if (!@mkdir($moduleBackupFolder)) {
                 throw new Exception("Could not create module backup folder!");
             }
         }
         $backupFolderName = $moduleBackupFolder . DIRECTORY_SEPARATOR . $moduleId . "_" . time();
         $moduleBasePath = $module->getBasePath();
         FileHelper::copyDirectory($moduleBasePath, $backupFolderName);
         FileHelper::removeDirectory($moduleBasePath);
     } else {
         //TODO: Delete directory
     }
     $this->flushCache();
 }
예제 #21
0
 public function init()
 {
     parent::init();
     // 默认配置
     $this->extJs['path'] = ArrayHelper::getValue($this->extJs, 'path', 'assets/dp/extjs/');
     $this->extJs['extendPath'] = ArrayHelper::getValue($this->extJs, 'extendPath', 'assets/dp/extjs-extend/');
     $this->extJs['appJsPath'] = ArrayHelper::getValue($this->extJs, 'appJsPath', $this->extJs['extendPath'] . 'app.js');
     $this->extJs['bootstrapJsPath'] = ArrayHelper::getValue($this->extJs, 'bootstrapJsPath', $this->extJs['extendPath'] . 'bootstrap.js');
     $this->extJs['bootstrapJsonPath'] = ArrayHelper::getValue($this->extJs, 'bootstrapJsonPath', $this->extJs['extendPath'] . 'bootstrap.json');
     $this->extJs['bootstrapCssPath'] = ArrayHelper::getValue($this->extJs, 'bootstrapCssPath', $this->extJs['path'] . 'packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css');
     // js路径
     $extJsSrcDir = Yii::getAlias($this->srcExtJsDir);
     $extJsSrcExtendDir = Yii::getAlias($this->srcExtJsExtendDir);
     $extJsDstDir = Yii::getAlias('@app/web/' . $this->extJs['path']);
     $extJsExtendDstDir = Yii::getAlias('@app/web/' . $this->extJs['extendPath']);
     // 创建符号连接所需的目录
     $extJsDstUpDir = dirname($extJsDstDir);
     if (!is_dir($extJsDstUpDir)) {
         @rmdir($extJsDstUpDir);
         if (!@FileHelper::createDirectory($extJsDstUpDir)) {
             if (!is_writeable(dirname($extJsDstUpDir))) {
                 throw new NotSupportedException('path: ' . dirname($extJsDstUpDir) . '目录没有写入权限');
             }
         }
     }
     $extJsExtendDstUpDir = dirname($extJsExtendDstDir);
     if (!is_dir($extJsExtendDstUpDir)) {
         @rmdir($extJsExtendDstUpDir);
         if (!@FileHelper::createDirectory($extJsExtendDstUpDir)) {
             if (!is_writeable(dirname($extJsExtendDstUpDir))) {
                 throw new NotSupportedException('path: ' . dirname($extJsExtendDstUpDir) . '目录没有写入权限');
             }
         }
     }
     // js目录创建符号连接
     if (!is_dir($extJsDstDir)) {
         if (!@symlink($extJsSrcDir, $extJsDstDir)) {
             if (!is_writeable($extJsDstUpDir)) {
                 throw new NotSupportedException('path: ' . $extJsDstUpDir . '目录没有写入权限');
             }
             FileHelper::copyDirectory($extJsSrcDir, $extJsDstDir);
         }
     }
     if (!is_dir($extJsExtendDstDir)) {
         if (!@symlink($extJsSrcExtendDir, $extJsExtendDstDir)) {
             if (!is_writeable($extJsExtendDstUpDir)) {
                 throw new NotSupportedException('path: ' . $extJsDstUpDir . '目录没有写入权限');
             }
             FileHelper::copyDirectory($extJsSrcExtendDir, $extJsExtendDstDir);
         }
     }
     $data = DpConfig::find()->all();
     $config = [];
     foreach ($data as $item) {
         $config[$item['name']] = $item['value'];
     }
     $this->config = $config;
     $this->identity = Yii::$app->user->identity;
 }
예제 #22
0
 /**
  * Publishes a file or a directory.
  *
  * This method will copy the specified file or directory to [[basePath]] so that
  * it can be accessed via the Web server.
  *
  * If the asset is a file, its file modification time will be checked to avoid
  * unnecessary file copying.
  *
  * If the asset is a directory, all files and subdirectories under it will be published recursively.
  * Note, in case $forceCopy is false the method only checks the existence of the target
  * directory to avoid repetitive copying (which is very expensive).
  *
  * By default, when publishing a directory, subdirectories and files whose name starts with a dot "."
  * will NOT be published. If you want to change this behavior, you may specify the "beforeCopy" option
  * as explained in the `$options` parameter.
  *
  * Note: On rare scenario, a race condition can develop that will lead to a
  * one-time-manifestation of a non-critical problem in the creation of the directory
  * that holds the published assets. This problem can be avoided altogether by 'requesting'
  * in advance all the resources that are supposed to trigger a 'publish()' call, and doing
  * that in the application deployment phase, before system goes live. See more in the following
  * discussion: http://code.google.com/p/yii/issues/detail?id=2579
  *
  * @param string $path the asset (file or directory) to be published
  * @param array $options the options to	be applied when publishing a directory.
  * The following options are supported:
  *
  * - beforeCopy: callback, a PHP callback that is called before copying each sub-directory or file.
  *   This option is used only when publishing a directory. If the callback returns false, the copy
  *   operation for the sub-directory or file will be cancelled.
  *   The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or
  *   file to be copied from, while `$to` is the copy target.
  * - afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied.
  *   This option is used only when publishing a directory. The signature of the callback is similar to that
  *   of `beforeCopy`.
  * - forceCopy: boolean, whether the directory being published should be copied even if
  *   it is found in the target directory. This option is used only when publishing a directory.
  *   You may want to set this to be true during the development stage to make sure the published
  *   directory is always up-to-date. Do not set this to true on production servers as it will
  *   significantly degrade the performance.
  * @return array the path (directory or file path) and the URL that the asset is published as.
  * @throws InvalidParamException if the asset to be published does not exist.
  */
 public function publish($path, $options = [])
 {
     $path = Yii::getAlias($path);
     if (isset($this->_published[$path])) {
         return $this->_published[$path];
     }
     if (!is_string($path) || ($src = realpath($path)) === false) {
         throw new InvalidParamException("The file or directory to be published does not exist: {$path}");
     }
     if (is_file($src)) {
         $dir = $this->hash(dirname($src) . filemtime($src));
         $fileName = basename($src);
         $dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
         $dstFile = $dstDir . DIRECTORY_SEPARATOR . $fileName;
         if (!is_dir($dstDir)) {
             FileHelper::createDirectory($dstDir, $this->dirMode, true);
         }
         if ($this->linkAssets) {
             if (!is_file($dstFile)) {
                 symlink($src, $dstFile);
             }
         } elseif (@filemtime($dstFile) < @filemtime($src)) {
             copy($src, $dstFile);
             if ($this->fileMode !== null) {
                 @chmod($dstFile, $this->fileMode);
             }
         }
         return $this->_published[$path] = [$dstFile, $this->baseUrl . "/{$dir}/{$fileName}"];
     } else {
         $dir = $this->hash($src . filemtime($src));
         $dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
         if ($this->linkAssets) {
             if (!is_dir($dstDir)) {
                 symlink($src, $dstDir);
             }
         } elseif (!is_dir($dstDir) || !empty($options['forceCopy'])) {
             $opts = ['dirMode' => $this->dirMode, 'fileMode' => $this->fileMode];
             if (isset($options['beforeCopy'])) {
                 $opts['beforeCopy'] = $options['beforeCopy'];
             } else {
                 $opts['beforeCopy'] = function ($from, $to) {
                     return strncmp(basename($from), '.', 1) !== 0;
                 };
             }
             if (isset($options['afterCopy'])) {
                 $opts['afterCopy'] = $options['afterCopy'];
             }
             FileHelper::copyDirectory($src, $dstDir, $opts);
         }
         return $this->_published[$path] = [$dstDir, $this->baseUrl . '/' . $dir];
     }
 }
예제 #23
0
 /**
  * Save file.
  *
  * @return bool
  */
 public function saveFile()
 {
     if (file_exists($this->pathTmp(true))) {
         FileHelper::copyDirectory($this->dirTmp(true), $this->dir(true));
         FileHelper::removeDirectory($this->dirTmp(true));
         return true;
     }
     // @codeCoverageIgnore
     return false;
 }
예제 #24
0
 /**
  * Publishes a directory.
  * @param string $src the asset directory to be published
  * @param array $options the options to be applied when publishing a directory.
  * The following options are supported:
  *
  * - only: array, list of patterns that the file paths should match if they want to be copied.
  * - except: array, list of patterns that the files or directories should match if they want to be excluded from being copied.
  * - caseSensitive: boolean, whether patterns specified at "only" or "except" should be case sensitive. Defaults to true.
  * - beforeCopy: callback, a PHP callback that is called before copying each sub-directory or file.
  *   This overrides [[beforeCopy]] if set.
  * - afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied.
  *   This overrides [[afterCopy]] if set.
  * - forceCopy: boolean, whether the directory being published should be copied even if
  *   it is found in the target directory. This option is used only when publishing a directory.
  *   This overrides [[forceCopy]] if set.
  *
  * @return array the path directory and the URL that the asset is published as.
  * @throws InvalidParamException if the asset to be published does not exist.
  */
 protected function publishDirectory($src, $options)
 {
     $dir = $this->hash($src);
     $dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
     if ($this->linkAssets) {
         if (!is_dir($dstDir)) {
             symlink($src, $dstDir);
         }
     } elseif (!empty($options['forceCopy']) || $this->forceCopy && !isset($options['forceCopy']) || !is_dir($dstDir)) {
         $opts = array_merge($options, ['dirMode' => $this->dirMode, 'fileMode' => $this->fileMode]);
         if (!isset($opts['beforeCopy'])) {
             if ($this->beforeCopy !== null) {
                 $opts['beforeCopy'] = $this->beforeCopy;
             } else {
                 $opts['beforeCopy'] = function ($from, $to) {
                     return strncmp(basename($from), '.', 1) !== 0;
                 };
             }
         }
         if (!isset($opts['afterCopy']) && $this->afterCopy !== null) {
             $opts['afterCopy'] = $this->afterCopy;
         }
         FileHelper::copyDirectory($src, $dstDir, $opts);
     }
     return [$dstDir, $this->baseUrl . '/' . $dir];
 }
예제 #25
0
파일: work.php 프로젝트: yiidottech/site
                    <div class="col-lg-9">

                        <div class="macbook-slider">

                            <div class="wrap">

                                <div class="royalSlider rsHydrogen">

                                    <?php 
foreach ($allProjects as $k => $v) {
    ?>

                                        <?php 
    if (!file_exists(\Yii::getAlias('@webroot') . '/demo/projects/' . $k)) {
        \yii\helpers\FileHelper::copyDirectory(\Yii::getAlias('@webroot') . '/demo/projects/oks-rebranding', \Yii::getAlias('@webroot') . '/demo/projects/' . $k);
    }
    ?>

                                        <?php 
    if ($v['featured']) {
        ?>
                                    <div class="slider-media project-slide">
                                        <figure>
                                            <img src="demo/projects/<?php 
        echo $k;
        ?>
/main.jpg" alt="<?php 
        echo $v['title'];
        ?>
" class="rsImg">