From df388217e48aa8a83a62452bc54591736f82c177 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 16 Oct 2018 22:47:28 -0600 Subject: [PATCH 1/3] Add new migration --- ..._033327_update_status_add_scope_column.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2018_10_17_033327_update_status_add_scope_column.php diff --git a/database/migrations/2018_10_17_033327_update_status_add_scope_column.php b/database/migrations/2018_10_17_033327_update_status_add_scope_column.php new file mode 100644 index 000000000..31d565a70 --- /dev/null +++ b/database/migrations/2018_10_17_033327_update_status_add_scope_column.php @@ -0,0 +1,32 @@ +string('scope')->default('public')->index()->after('is_nsfw'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('statuses', function (Blueprint $table) { + $table->dropColumn('scope'); + }); + } +} From 13fc66e92065cf38e6c8456cef0d71b8807f169a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 16 Oct 2018 22:54:27 -0600 Subject: [PATCH 2/3] Add update command --- app/Console/Commands/UpdateCommand.php | 173 +++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 app/Console/Commands/UpdateCommand.php diff --git a/app/Console/Commands/UpdateCommand.php b/app/Console/Commands/UpdateCommand.php new file mode 100644 index 000000000..d39d89e20 --- /dev/null +++ b/app/Console/Commands/UpdateCommand.php @@ -0,0 +1,173 @@ +verifyVersion(); + } + + public function verifyVersion() + { + $this->callSilent('config:cache'); + $this->version = config('pixelfed.version'); + + $known = in_array($this->version, $this->versions); + if($known == false) { + $this->error('Unknown version found, aborting...'); + exit; + } + $this->updateStrategy($this->version); + } + + public function updateStrategy($version) + { + switch ($version) { + case '0.1.8': + $this->info('You are running an older version that doesn\'t require any updates!'); + break; + case '0.1.9': + $this->update019(); + break; + + default: + # code... + break; + } + } + + public function update019() + { + $this->buildVersionFile(); + $v = $this->getVersionFile(); + if($v['updated'] == true) { + $this->info('Already up to date!'); + exit; + } + $exists = Schema::hasColumn('statuses','scope'); + if(!$exists) { + $this->error('You need to run the migrations before you proceed with this update.'); + if($this->confirm('Do you want to run the migrations?')) { + $this->callSilent('migrate'); + } else { + exit; + } + } + $statusCount = Status::count(); + $this->info('Running updates ...'); + $bar = $this->output->createProgressBar($statusCount); + Status::chunk(200, function($statuses) use ($bar) { + + foreach($statuses as $status) { + $ts = $status->updated_at; + $status->scope = $status->visibility; + $status->updated_at = $ts; + $status->save(); + + if($status->firstMedia()) { + $media = $status->firstMedia(); + if(in_array($media->mime, ['image/jpeg', 'image/png'])) { + ImageThumbnail::dispatch($media); + } + } + $bar->advance(); + } + }); + $this->updateVersionFile('0.1.9', true); + $bar->finish(); + } + + protected function buildVersionFile() + { + $path = storage_path('app/version.json'); + if(is_file($path) == false) { + $contents = json_encode([ + 'version' => $this->version, + 'updated' => false, + 'timestamp' => date('c') + ], JSON_PRETTY_PRINT); + file_put_contents($path, $contents); + } + } + + protected function getVersionFile() + { + $path = storage_path('app/version.json'); + if(is_file($path) == false) { + $contents = [ + 'version' => $this->version, + 'updated' => false, + 'timestamp' => date('c') + ]; + $json = json_encode($contents, JSON_PRETTY_PRINT); + file_put_contents($path, $json); + return $contents; + } else { + return json_decode(file_get_contents($path), true); + } + } + + protected function updateVersionFile($version, $updated = false) { + $path = storage_path('app/version.json'); + if(is_file($path) == false) { + return; + } + $contents = [ + 'version' => $version, + 'updated' => $updated, + 'timestamp' => date('c') + ]; + $json = json_encode($contents, JSON_PRETTY_PRINT); + file_put_contents($path, $json); + } +} From 3aa65b857c51832e03a61efad2b50b3e277728a1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 16 Oct 2018 22:54:52 -0600 Subject: [PATCH 3/3] Bump version --- config/pixelfed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/pixelfed.php b/config/pixelfed.php index b6e80e3fe..2b2bd9b74 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -23,7 +23,7 @@ return [ | This value is the version of your PixelFed instance. | */ - 'version' => '0.1.8', + 'version' => '0.1.9', /* |--------------------------------------------------------------------------