blue-twilight/app/Console/Commands/ProcessUploadCommand.php

81 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Album;
use App\Photo;
use App\Upload;
use App\UploadPhoto;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class ProcessUploadCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'twilight:process-uploads';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Processes uploads made through the web application.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$uploadsToProcess = Upload::where([
['is_completed', false],
['is_processing', false]
])
->orderBy('created_at', 'desc')
->get();
foreach ($uploadsToProcess as $upload)
{
$this->output->writeln(sprintf('Processing upload #%d', $upload->id));
$this->handleUpload($upload);
}
}
private function handleUpload(Upload $upload)
{
$photos = $upload->uploadPhotos;
foreach ($photos as $photo)
{
$this->handlePhoto($photo);
}
}
private function handlePhoto(UploadPhoto $uploadPhoto)
{
$photo = $uploadPhoto->photo;
$this->output->writeln(sprintf('Analysing photo #%d: %s', $photo->id, $photo->name));
$album = $photo->album;
$photoFile = Storage::path(sprintf('albums/%s/%s', $album->url_alias, $photo->file_name), $album->getUploadDisk());
dump($photoFile);
dump(@exif_read_data($photoFile));
}
}