2023_02_01_182021_create_invoice_settings.php 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. use App\Classes\LegacySettingsMigration;
  3. use Illuminate\Support\Facades\DB;
  4. class CreateInvoiceSettings extends LegacySettingsMigration
  5. {
  6. public function up(): void
  7. {
  8. $table_exists = DB::table('settings_old')->exists();
  9. // Get the user-set configuration values from the old table.
  10. $this->migrator->add('invoice.company_address', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_ADDRESS') : null);
  11. $this->migrator->add('invoice.company_mail', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_MAIL') : null);
  12. $this->migrator->add('invoice.company_name', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_NAME') : null);
  13. $this->migrator->add('invoice.company_phone', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_PHONE') : null);
  14. $this->migrator->add('invoice.company_vat', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_VAT') : null);
  15. $this->migrator->add('invoice.company_website', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:COMPANY_WEBSITE') : null);
  16. $this->migrator->add('invoice.enabled', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:ENABLED', false) : false);
  17. $this->migrator->add('invoice.prefix', $table_exists ? $this->getOldValue('SETTINGS::INVOICE:PREFIX') : null);
  18. }
  19. public function down(): void
  20. {
  21. DB::table('settings_old')->insert([
  22. [
  23. 'key' => 'SETTINGS::INVOICE:COMPANY_ADDRESS',
  24. 'value' => $this->getNewValue('company_address', 'invoice'),
  25. 'type' => 'string',
  26. 'description' => 'The address of the company.',
  27. ],
  28. [
  29. 'key' => 'SETTINGS::INVOICE:COMPANY_MAIL',
  30. 'value' => $this->getNewValue('company_mail', 'invoice'),
  31. 'type' => 'string',
  32. 'description' => 'The email address of the company.',
  33. ],
  34. [
  35. 'key' => 'SETTINGS::INVOICE:COMPANY_NAME',
  36. 'value' => $this->getNewValue('company_name', 'invoice'),
  37. 'type' => 'string',
  38. 'description' => 'The name of the company.',
  39. ],
  40. [
  41. 'key' => 'SETTINGS::INVOICE:COMPANY_PHONE',
  42. 'value' => $this->getNewValue('company_phone', 'invoice'),
  43. 'type' => 'string',
  44. 'description' => 'The phone number of the company.',
  45. ],
  46. [
  47. 'key' => 'SETTINGS::INVOICE:COMPANY_VAT',
  48. 'value' => $this->getNewValue('company_vat', 'invoice'),
  49. 'type' => 'string',
  50. 'description' => 'The VAT number of the company.',
  51. ],
  52. [
  53. 'key' => 'SETTINGS::INVOICE:COMPANY_WEBSITE',
  54. 'value' => $this->getNewValue('company_website', 'invoice'),
  55. 'type' => 'string',
  56. 'description' => 'The website of the company.',
  57. ],
  58. [
  59. 'key' => 'SETTINGS::INVOICE:ENABLED',
  60. 'value' => $this->getNewValue('enabled', 'invoice'),
  61. 'type' => 'boolean',
  62. 'description' => 'Enable or disable the invoice system.',
  63. ],
  64. [
  65. 'key' => 'SETTINGS::INVOICE:PREFIX',
  66. 'value' => $this->getNewValue('prefix', 'invoice'),
  67. 'type' => 'string',
  68. 'description' => 'The prefix of the invoice.',
  69. ],
  70. ]);
  71. try {
  72. $this->migrator->delete('invoice.company_address');
  73. $this->migrator->delete('invoice.company_mail');
  74. $this->migrator->delete('invoice.company_name');
  75. $this->migrator->delete('invoice.company_phone');
  76. $this->migrator->delete('invoice.company_vat');
  77. $this->migrator->delete('invoice.company_website');
  78. $this->migrator->delete('invoice.enabled');
  79. $this->migrator->delete('invoice.prefix');
  80. } catch (Exception $e) {
  81. // Do nothing
  82. }
  83. }
  84. }