1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Console\Commands;
- use App\Http\Models\Site;
- use App\Http\Services\TemplateLibraryApiService;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class TemplateLibrarySyncPictures extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'sync_pictures:template_library';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- private $templateLibraryApiService;
- public function __construct(TemplateLibraryApiService $templateLibraryApiService)
- {
- parent::__construct();
- $this->templateLibraryApiService = $templateLibraryApiService;
- }
- const HOST = '121.199.40.85';
- const USER = 'root';
- const PASSWORD = 'JGJHD84@8&a';
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- /*try {
- $ssh2 = ssh2_connect(self::HOST, 22);
- ssh2_auth_password($ssh2, self::USER, self::PASSWORD);
- $siteId = 974;
- $domain = Site::query()->where('id', $siteId)->value('domain');
- //远程目录
- $targetDirectory = '/www/wwwroot/' . $domain . '/sepSsr/uploads';
- //递归创建目录
- $sftp = ssh2_sftp($ssh2);
- ssh2_sftp_mkdir($sftp, $targetDirectory, 0755, true);
- $connection = DB::connection($this->templateLibraryApiService->connection($siteId));
- $imagesList = $connection->table('image')->get();
- foreach ($imagesList as $item) {
- $imagePathArray = explode('storage', $item->src);
- $fileName = explode('/', $imagePathArray[1]);
- $file = array_pop($fileName);
- //本地目录
- $sourceDirectory = base_path() . '/storage/app/public' . $imagePathArray[1];
- $stream = ssh2_scp_send($ssh2, $sourceDirectory, $targetDirectory . '/' . $file, 0644);
- if ($stream) {
- $connection->table('image')->where('id', $item->id)->update(['is_synchronize' => 1]);
- }
- }
- } catch (\Exception $exception) {
- Log::info(date('Y-m-d H:i:s') . 'sync_pictures error!' . $exception->getMessage());
- }
- Log::info(date('Y-m-d H:i:s') . 'sync_pictures success!');*/
- }
- }
|