1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-26 09:46:49 +00:00
pixelfed/app/Console/Commands/UpdateCommand.php

87 lines
2.3 KiB
PHP
Raw Normal View History

2018-10-17 04:54:27 +00:00
<?php
namespace App\Console\Commands;
use Schema;
use Illuminate\Console\Command;
use App\Jobs\ImageOptimizePipeline\ImageThumbnail;
class UpdateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run pixelfed schema updates between versions.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2019-03-02 06:20:14 +00:00
$this->update();
2018-10-17 04:54:27 +00:00
}
2019-03-02 06:20:14 +00:00
public function update()
2018-10-17 04:54:27 +00:00
{
$v = $this->getVersionFile();
2019-03-02 06:20:14 +00:00
if($v && isset($v['commit_hash']) && $v['commit_hash'] == exec('git rev-parse HEAD') && \App\StatusHashtag::whereNull('profile_id')->count() == 0) {
$this->info('No updates found.');
return;
2018-11-24 21:03:15 +00:00
}
2019-03-02 06:28:37 +00:00
$bar = $this->output->createProgressBar(\App\StatusHashtag::whereNull('profile_id')->count());
2019-03-02 06:20:14 +00:00
\App\StatusHashtag::whereNull('profile_id')->with('status')->chunk(50, function($sh) use ($bar) {
foreach($sh as $status_hashtag) {
if(!$status_hashtag->status) {
$status_hashtag->delete();
} else {
$status_hashtag->profile_id = $status_hashtag->status->profile_id;
$status_hashtag->save();
2018-11-24 21:03:15 +00:00
}
$bar->advance();
}
});
2019-03-02 06:20:14 +00:00
$this->updateVersionFile();
2018-11-24 21:03:15 +00:00
$bar->finish();
}
2018-10-17 04:54:27 +00:00
protected function getVersionFile()
{
$path = storage_path('app/version.json');
2019-03-02 06:20:14 +00:00
return is_file($path) ?
json_decode(file_get_contents($path), true) :
false;
2018-10-17 04:54:27 +00:00
}
2019-03-02 06:20:14 +00:00
protected function updateVersionFile() {
2018-10-17 04:54:27 +00:00
$path = storage_path('app/version.json');
$contents = [
2019-03-02 06:20:14 +00:00
'commit_hash' => exec('git rev-parse HEAD'),
'version' => config('pixelfed.version'),
2018-10-17 04:54:27 +00:00
'timestamp' => date('c')
];
$json = json_encode($contents, JSON_PRETTY_PRINT);
file_put_contents($path, $json);
}
}