示例#1
0
 public function init()
 {
     parent::init();
     $this->tmpPath = P::getAlias($this->tmpPath);
     if (!is_dir($this->tmpPath)) {
         FileHelper::createDirectory($this->tmpPath, $this->tmpDirMode, true);
     }
 }
 public function run()
 {
     if (empty($this->language)) {
         throw new \yii\base\Exception('Language must be specified.');
     }
     if (empty($this->category)) {
         throw new \yii\base\Exception('Message category must be specified.');
     }
     if (empty($this->targetAttribute)) {
         throw new \yii\base\Exception('Target model attribute must be specified.');
     }
     FileHelper::loadFile($this->sourceUrl, ['destDir' => $this->tmpPath, 'onLoad' => [$this, 'resolveFile']]);
     FileHelper::removeDirectory($this->tmpPath);
 }
示例#3
0
 public function resolveFile($file)
 {
     if (!is_file($file)) {
         throw new \yii\base\Exception('Source file not found.');
     }
     if (!class_exists('\\ZipArchive')) {
         throw new \yii\base\Exception('Not exist ZipArchive class, your must install PECL zip library.');
     }
     $z = new \ZipArchive();
     $z->open($file);
     $z->extractTo($this->tmpPath);
     $z->close();
     $files = FileHelper::findFiles($this->tmpPath);
     $names = [self::CSV_FILE_LOCATION, self::CSV_FILE_BLOCKS];
     foreach ($names as $name) {
         foreach ($files as $fileCsv) {
             if (!FileHelper::filterPath($fileCsv, ['only' => [$name], 'basePath' => realpath($fileCsv)])) {
                 continue;
             }
             $this->resolveCsv($name, $fileCsv);
         }
     }
 }
示例#4
0
 public function run()
 {
     FileHelper::loadFile($this->sourceUrl, ['destDir' => $this->tmpPath, 'onLoad' => [$this, 'resolveFile']]);
     FileHelper::removeDirectory($this->tmpPath);
 }