removeDirectory() 공개 정적인 메소드

Removes a directory (and all its content) recursively.
public static removeDirectory ( string $dir, array $options = [] )
$dir string the directory to be deleted recursively.
$options array options for directory remove. Valid options are: - traverseSymlinks: boolean, whether symlinks to the directories should be traversed too. Defaults to `false`, meaning the content of the symlinked directory would not be deleted. Only symlink would be removed in that default case.
예제 #1
1
 public function attachFile()
 {
     try {
         $model = $this->owner;
         $fileName = Inflector::slug($model->fullAddress) . '.pdf';
         $folder = $this->getModelSubDir() . '/';
         $model->pdf_path = $fileName;
         $pdf = new Pdf(['mode' => Pdf::MODE_UTF8, 'destination' => Pdf::DEST_FILE, 'content' => Yii::$app->view->render('@frontend/views/site/real-estate/print', ['model' => $model]), 'methods' => ['SetHeader' => ['Rapport ' . $model->fullAddress], 'SetFooter' => ['|Pagina {PAGENO}|']], 'filename' => Yii::getAlias('@uploadsBasePath') . "/files/{$folder}{$fileName}"]);
         $this->file = $pdf;
         BaseFileHelper::removeDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}");
         if (!BaseFileHelper::createDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}")) {
             throw new Exception(Yii::t('app', 'Failed to create the file upload directory'));
         }
         // Save and update model
         $pdf->render();
         $model->save();
         return true;
     } catch (yii\base\Exception $e) {
         return $e->getMessage();
     }
 }
예제 #2
0
 public static function delPhotos($sale_id)
 {
     $model = self::findAll(['sale_id' => $sale_id]);
     foreach ($model as $item) {
         $item->delete();
     }
     $path = Yii::$app->params['uploadSalePath'] . DIRECTORY_SEPARATOR . $sale_id;
     BaseFileHelper::removeDirectory($path);
 }
예제 #3
0
 public function clearCache()
 {
     $subDir = $this->getSubDur();
     $dirToRemove = $this->getModule()->getCachePath() . DIRECTORY_SEPARATOR . $subDir;
     if (preg_match('/' . preg_quote($this->modelName, '/') . DIRECTORY_SEPARATOR, $dirToRemove)) {
         BaseFileHelper::removeDirectory($dirToRemove);
     }
     return true;
 }
예제 #4
0
 /**
  * @return static
  */
 public function flushPublishedCopies()
 {
     $module = $this->getModule();
     $subDirectory = $this->getSubDirectory();
     $dirToRemove = "{$module->publishPath}{$module->ds}{$subDirectory}";
     $quotedModelName = preg_quote($this->modelName, '/');
     if (preg_match("@{$quotedModelName}@", $dirToRemove)) {
         BaseFileHelper::removeDirectory($dirToRemove);
     }
     return $this;
 }
 public function attachFile()
 {
     try {
         $model = $this->owner;
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->validate() && $model->file) {
             $fileName = Inflector::slug($model->file->baseName) . '.' . $model->file->extension;
             $folder = $this->getModelSubDir() . '/';
             $model->path = $fileName;
             BaseFileHelper::removeDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}");
             if (!BaseFileHelper::createDirectory(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}")) {
                 throw new Exception(Yii::t('app', 'Failed to create the file upload directory'));
             }
             $model->file->saveAs(Yii::getAlias('@uploadsBasePath') . "/files/{$folder}{$model->path}");
             $model->save();
         }
         return true;
     } catch (yii\base\Exception $e) {
         return $e->getMessage();
     }
 }
예제 #6
0
 /**
  * Clear all images cache (and resized copies)
  * @return bool
  */
 public function clearImagesCache()
 {
     $cachePath = $this->getModule()->getCachePath();
     $subdir = $this->getModule()->getModelSubDir($this->owner);
     $dirToRemove = $cachePath . '/' . $subdir;
     if (preg_match('/' . preg_quote($cachePath, '/') . '/', $dirToRemove)) {
         BaseFileHelper::removeDirectory($dirToRemove);
         //exec('rm -rf ' . $dirToRemove);
         return true;
     } else {
         return false;
     }
 }
예제 #7
0
파일: Sale.php 프로젝트: dench/resistor
 public function afterDelete()
 {
     SalePhoto::delPhotos($this->id);
     $path = Yii::$app->params['uploadSalePath'] . DIRECTORY_SEPARATOR . $this->id;
     BaseFileHelper::removeDirectory($path);
     if (!self::findOne(['object_id' => $this->object_id])) {
         Object::findOne($this->object_id)->delete();
     }
     return parent::afterDelete();
 }
예제 #8
0
 private function removeUploadDir($dir)
 {
     BaseFileHelper::removeDirectory(Album::getUploadPath() . $dir);
 }
예제 #9
0
 /**
  * Remove all cached images
  */
 public function clearAll()
 {
     @BaseFileHelper::removeDirectory($this->sourcePath . $this->cachePath . '/imagecache/');
 }
 private function removeUploadDir($dir)
 {
     BaseFileHelper::removeDirectory(PhotoLibrary::getUploadPath() . $dir);
 }
예제 #11
0
 public function removeItemFolder($related, $itemId)
 {
     $uploadPath = $this->routes['uploadPath'];
     $uploadPath .= '/' . $related;
     $structure = "{$this->routes['baseUrl']}/{$uploadPath}";
     $basePath = Yii::getAlias($this->routes['basePath']);
     $dir = "{$basePath}{$structure}/{$itemId}";
     \yii\helpers\BaseFileHelper::removeDirectory($dir);
 }
예제 #12
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         ActivityImage::deleteAll(['id_activity' => $this->id]);
         BaseFileHelper::removeDirectory(Yii::getAlias('@activity/') . $this->id);
         return true;
     } else {
         return false;
     }
 }
예제 #13
0
 public function actionIntegration()
 {
     $dsn_array_attribute = explode('=', Yii::$app->db->dsn);
     $db_name = $dsn_array_attribute[2];
     $table_prefix = Yii::$app->db->tablePrefix;
     BaseFileHelper::createDirectory($this->tempDir, 0777);
     foreach ($this->files as $table_name => $filename) {
         $zip_name = $this->tempDir . $filename;
         if (!file_exists($zip_name)) {
             if (!($tmp_file = fopen($zip_name, 'w'))) {
                 return;
             }
             $curl = curl_init();
             $url = $this->baseUrl . $filename;
             curl_setopt($curl, CURLOPT_URL, $url);
             curl_setopt($curl, CURLOPT_FILE, $tmp_file);
             curl_setopt($curl, CURLOPT_HEADER, 0);
             curl_exec($curl);
             curl_close($curl);
             fclose($tmp_file);
         }
         if (preg_match('/\\.zip$/', $zip_name)) {
             $zip = new \ZipArchive();
             $zip->open($zip_name);
             $zip->extractTo($this->tempDir);
         }
         $unziped_name = str_replace('.zip', '.txt', $zip_name);
         if ($table_name == 'geoname_alternative_name') {
             $new_unzipped_name = $this->tempDir . 'ru_names.txt';
             `grep -P '^\\d+\t\\d+\tru\t' {$unziped_name} > {$new_unzipped_name}`;
             $unziped_name = $new_unzipped_name;
         } else {
             if ($table_name == 'geoname_country') {
                 $new_unzipped_name = $this->tempDir . 'countryInfo_fixed.txt';
                 `grep -Pv '^#.*\$' {$unziped_name} > {$new_unzipped_name}`;
                 $unziped_name = $new_unzipped_name;
             }
         }
         $fields = ArrayHelper::getColumn(Yii::$app->db->createCommand("SHOW COLUMNS FROM {$table_prefix}{$table_name}")->query(), 'Field');
         Yii::$app->db->createCommand("TRUNCATE {$table_prefix}{$table_name}")->query();
         $sql = "LOAD DATA LOCAL INFILE '" . $unziped_name . "' INTO TABLE " . $table_prefix . $table_name . ' CHARACTER SET utf8 FIELDS TERMINATED BY \\"\\t\\" LINES TERMINATED BY \\"\\n\\" (' . implode(', ', $fields) . ')';
         $db = Yii::$app->db;
         $cmd = "mysql --local-infile=1 -u{$db->username} -p{$db->password} {$db_name} -e \"{$sql}\" \n";
         `{$cmd}`;
     }
     BaseFileHelper::removeDirectory($this->tempDir);
     Yii::$app->db->createCommand("DELETE FROM {$table_prefix}geoname_country WHERE geoname_id = 0")->query();
     $sql = "SELECT {$table_prefix}geoname_country.*,\n            (SELECT alternate_name FROM {$table_prefix}geoname_alternative_name WHERE {$table_prefix}geoname_alternative_name.geoname_id = {$table_prefix}geoname_country.geoname_id LIMIT 0,1) as ru_name\n            FROM {$table_prefix}geoname_country ";
     $geoname_countries = Yii::$app->db->createCommand($sql)->query();
     foreach ($geoname_countries as $geoname_country) {
         if (!($country = Country::findOne(['iso' => $geoname_country['iso']]))) {
             $country = new Country();
         }
         $attributes = ['iso' => $geoname_country['iso'], 'title' => $geoname_country['ru_name'], 'worldpart' => $geoname_country['continent'], 'geoname_id' => $geoname_country['geoname_id'], 'is_published' => 1];
         if (!$country->getIsNewRecord()) {
             $attributes = ['geoname_id' => $geoname_country['geoname_id']];
         }
         $capital_id = $this->getCapitalIdByName($geoname_country['capital'], $geoname_country['iso'], $table_prefix);
         if ($capital_id && $country->capital_id != $capital_id) {
             $attributes['capital_id'] = $capital_id;
         }
         $country->setAttributes($attributes);
         $country->save();
     }
     $country_ids = [];
     foreach (Yii::$app->db->createCommand("SELECT id, iso FROM {$table_prefix}country")->query() as $item) {
         $country_ids[$item['iso']] = $item['id'];
     }
     $sql = "SELECT\n              {$table_prefix}geoname_city.geoname_id as geoname_id,\n              {$table_prefix}geoname_city.alternate_names as alternate_names,\n              {$table_prefix}geoname_city.latitude as latitude,\n              {$table_prefix}geoname_city.longitude as longitude,\n              {$table_prefix}geoname_city.country_code as country_code,\n              {$table_prefix}geoname_alternative_name.alternate_name as ru_name\n            FROM {$table_prefix}geoname_city\n            JOIN {$table_prefix}geoname_alternative_name ON {$table_prefix}geoname_alternative_name.geoname_id = {$table_prefix}geoname_city.geoname_id\n            GROUP BY geoname_id ";
     $geoname_cities = Yii::$app->db->createCommand($sql)->query();
     foreach ($geoname_cities as $geoname_city) {
         if (!$geoname_city['country_code']) {
             continue;
         }
         if (!isset($country_ids[$geoname_city['country_code']])) {
             continue;
         }
         if (!$geoname_city['geoname_id']) {
             continue;
         }
         $russian_city_title = trim($geoname_city['ru_name']);
         $russian_city_title = mb_convert_case($russian_city_title, MB_CASE_TITLE, 'UTF-8');
         if (!preg_match('/[а-яА-я]/', $russian_city_title)) {
             continue;
         }
         if (!($city = City::findOne(['geoname_id' => $geoname_city['geoname_id']]))) {
             $city = new City();
         }
         $identifier = strtolower($this->translitRussian($russian_city_title));
         $identifier = str_replace('  ', ' ', $identifier);
         $identifier = str_replace(' ', '-', $identifier);
         $attributes = ['title' => $russian_city_title, 'latitude' => $geoname_city['latitude'], 'longitude' => $geoname_city['longitude'], 'identifier' => $identifier, 'geoname_id' => $geoname_city['geoname_id'], 'country_id' => $country_ids[$geoname_city['country_code']], 'is_published' => 1];
         if (!$city->getIsNewRecord()) {
             unset($attributes['title']);
             unset($attributes['identifier']);
             unset($attributes['country_id']);
             unset($attributes['is_published']);
         }
         $city->setAttributes($attributes);
         $city->save();
     }
 }
 private function removeUploadDir($dir)
 {
     BaseFileHelper::removeDirectory(Employee::getUploadPath() . '/' . $dir);
 }
예제 #15
0
 private function removePhotosUploadDir($dir)
 {
     BaseFileHelper::removeDirectory(Article::getUploadPhotosPath() . $dir);
 }
예제 #16
0
 protected function tearDown()
 {
     BaseFileHelper::removeDirectory(Yii::getAlias('@app') . '/tests/unit/data/imgStore');
     BaseFileHelper::removeDirectory(Yii::getAlias('@app') . '/tests/unit/data/imgCache');
 }
 /**
  * Cleanup all files in the zip output path.
  */
 protected function cleanup()
 {
     BaseFileHelper::removeDirectory($this->getZipOutputPath());
 }