$id]); if ($config) { $fileTemplate = $config->file ? [ 'filePatch' => $config->file->getFilePath(false, true), 'border_top' => $config->border_top, 'border_right' => $config->border_right, 'border_left' => $config->border_left, 'border_bottom' => $config->border_bottom, ] : []; if ($config->file) { $config->file->downloadOriginal(); } $flag = true; $offset = $this->beginFrom; $limit = 100;//000; while ($flag) { $query = File::find()->andWhere(['module' => $config->module])->orderBy(['id'=>SORT_ASC])->offset($offset)->limit($limit); if(!empty($this->onlyFile)) { $query->andWhere(['id' => explode(',', $this->onlyFile)]); } $files = (array) $query->all(); $offset = $offset + count($files); $flag = empty($files) || count($files) < $limit ? false :true; $fileDelete = []; foreach ($files as $file) { try { $file->downloadOriginal(); $file->resize($config->type, $config->height, $config->width, $config->crop, $config->cut, $config->addBorder, true, $fileTemplate, $config->quality); if ($file->cropFile) { try { unlink($file->cropFile); } catch (\Exception $ex) { $fileDelete[] = $file->cropFile; } } if (\Yii::$app->has('s3')) { $s3 = \Yii::$app->get('s3'); if (file_exists($file->getFilePath($config->type, true))) { $s3->upload($file->getFilePath($config->type), $file->getFilePath($config->type, true)); try { unlink($file->getFilePath($config->type, true)); } catch (\Exception $ex) { $fileDelete[] = $file->getFilePath($config->type, true); } } } } catch (\Exception | \ValueError $ex) { echo "fileId {$file->id}; Exception: {$ex->getMessage()} \n"; } } echo "обработано: {$offset} \n"; foreach ($fileDelete as $value) { @unlink($value); } } } return ExitCode::OK; } }