| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2024-11-25 04:18:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * UpgradeDatabase.php | 
					
						
							| 
									
										
										
										
											2020-01-23 20:35:02 +01:00
										 |  |  |  * Copyright (c) 2020 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-17 12:09:03 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Console\Commands\Upgrade; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 18:58:06 +01:00
										 |  |  | set_time_limit(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-20 07:16:56 +02:00
										 |  |  | use FireflyIII\Console\Commands\ShowsFriendlyMessages; | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  | use Illuminate\Console\Command; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-27 06:48:58 +01:00
										 |  |  | class UpgradesDatabase extends Command | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-06-20 07:16:56 +02:00
										 |  |  |     use ShowsFriendlyMessages; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 08:10:59 +01:00
										 |  |  |     protected $description = 'Upgrades the database to the latest version.'; | 
					
						
							| 
									
										
										
										
											2023-06-02 07:36:17 +02:00
										 |  |  |     protected $signature   = 'firefly-iii:upgrade-database {--F|force : Force all upgrades.}'; | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Execute the console command. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-06-07 17:57:46 +02:00
										 |  |  |     public function handle(): int | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-08-05 17:07:19 +02:00
										 |  |  |         $this->callInitialCommands(); | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  |         $commands = [ | 
					
						
							| 
									
										
										
										
											2024-12-27 06:48:58 +01:00
										 |  |  |             'upgrade:480-transaction-identifiers', | 
					
						
							|  |  |  |             'upgrade:480-migrate-to-groups', | 
					
						
							|  |  |  |             'upgrade:480-account-currencies', | 
					
						
							|  |  |  |             'upgrade:480-transfer-currencies', | 
					
						
							|  |  |  |             'upgrade:480-currency-information', | 
					
						
							|  |  |  |             'upgrade:480-notes', | 
					
						
							|  |  |  |             'upgrade:480-attachments', | 
					
						
							|  |  |  |             'upgrade:480-bills-to-rules', | 
					
						
							|  |  |  |             'upgrade:480-budget-limit-currencies', | 
					
						
							|  |  |  |             'upgrade:480-cc-liabilities', | 
					
						
							|  |  |  |             'upgrade:480-journal-meta-data', | 
					
						
							|  |  |  |             'upgrade:480-account-meta', | 
					
						
							|  |  |  |             'upgrade:481-recurrence-meta', | 
					
						
							|  |  |  |             'upgrade:500-tag-locations', | 
					
						
							|  |  |  |             'upgrade:560-liabilities', | 
					
						
							|  |  |  |             'upgrade:600-liabilities', | 
					
						
							|  |  |  |             'upgrade:550-budget-limit-periods', | 
					
						
							|  |  |  |             'upgrade:600-rule-actions', | 
					
						
							|  |  |  |             'upgrade:610-account-balance', | 
					
						
							| 
									
										
										
										
											2024-12-27 07:24:47 +01:00
										 |  |  |             'upgrade:610-currency-preferences', | 
					
						
							|  |  |  |             'upgrade:610-currency-preferences', | 
					
						
							|  |  |  |             'upgrade:620-piggy-banks', | 
					
						
							|  |  |  |             'upgrade:620-native-amounts', | 
					
						
							| 
									
										
										
										
											2024-04-01 18:03:43 +02:00
										 |  |  |             'firefly-iii:correct-database', | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  |         ]; | 
					
						
							|  |  |  |         $args     = []; | 
					
						
							|  |  |  |         if ($this->option('force')) { | 
					
						
							|  |  |  |             $args = ['--force' => true]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         foreach ($commands as $command) { | 
					
						
							| 
									
										
										
										
											2023-06-20 07:16:56 +02:00
										 |  |  |             $this->friendlyLine(sprintf('Now executing %s', $command)); | 
					
						
							| 
									
										
										
										
											2023-04-16 07:33:12 +02:00
										 |  |  |             $this->call($command, $args); | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-08-05 17:07:19 +02:00
										 |  |  |         // set new DB version.
 | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         app('fireflyconfig')->set('db_version', (int) config('firefly.db_version')); | 
					
						
							| 
									
										
										
										
											2019-08-05 17:07:19 +02:00
										 |  |  |         // index will set FF3 version.
 | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         app('fireflyconfig')->set('ff3_version', (string) config('firefly.version')); | 
					
						
							| 
									
										
										
										
											2020-03-21 15:43:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 17:57:46 +02:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-05 17:07:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private function callInitialCommands(): void | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-05-07 20:17:29 +02:00
										 |  |  |         $this->call('migrate', ['--seed' => true, '--force' => true, '--no-interaction' => true]); | 
					
						
							| 
									
										
										
										
											2024-12-27 06:48:58 +01:00
										 |  |  |         $this->call('upgrade:600-pgsql-sequences'); | 
					
						
							|  |  |  |         $this->call('upgrade:480-decrypt-all'); | 
					
						
							| 
									
										
										
										
											2019-08-05 17:07:19 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-03-18 16:53:05 +01:00
										 |  |  | } |