Migrations fixes

- Minor formating changes
- Adding migration helper calls where needed
- Adding locale helper calls where needed
- Add use statement to tax_lib for sale_lib
- pass gcaptcha enabled to the login view after checking to see if the key exists so that we don't get code errors before migrations 20170501150000
- Fixed getWhere in Appconfig model
This commit is contained in:
objecttothis
2023-02-03 18:11:00 +04:00
committed by Steve Ireland
parent d6d7b7adc6
commit cdb21d3e4c
29 changed files with 74 additions and 41 deletions

View File

@@ -43,7 +43,11 @@ class OSPOSRules
}
//GCaptcha Check
if(config('OSPOS')->settings['gcaptcha_enable'])
$gcaptcha_enabled = array_key_exists('gcaptcha_enable', config('OSPOS')->settings)
? config('OSPOS')->settings['gcaptcha_enable']
: false;
if($gcaptcha_enabled)
{
$g_recaptcha_response = $this->request->getPost('g-recaptcha-response');

View File

@@ -19,10 +19,17 @@ class Login extends BaseController
if(!$this->employee->is_logged_in())
{
$migration = new MY_Migration(config('Migrations'));
//The gcaptcha_enable key was not added to app settings until 3.1.1. Without this check we get an error
$gcaptcha_enabled = array_key_exists('gcaptcha_enable', config('OSPOS')->settings)
? config('OSPOS')->settings['gcaptcha_enable']
: false;
$data = [
'has_errors' => false,
'is_latest' => $migration->is_latest(),
'latest_version' => $migration->get_last_migration()
'latest_version' => $migration->get_last_migration(),
'gcaptcha_enabled' => $gcaptcha_enabled
];
if(strtolower($this->request->getMethod()) !== 'post')

View File

@@ -13,6 +13,7 @@ class Migration_Upgrade_To_3_1_1 extends Migration
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.0.2_to_3.1.1.sql');
}
@@ -20,4 +21,4 @@ class Migration_Upgrade_To_3_1_1 extends Migration
{
}
}
}

View File

@@ -8,8 +8,6 @@ use CodeIgniter\Database\Migration;
use CodeIgniter\Database\ResultInterface;
/**
*
*
* @property tax_lib tax_lib
* @property appconfig appconfig
*/
@@ -25,19 +23,18 @@ class Migration_Sales_Tax_Data extends Migration
public function __construct()
{
parent::__construct();
$this->tax_lib = new Tax_lib();
$this->appconfig = model('Appconfig');
}
//TODO: we need to figure out why we get a server error when uncommented portions of this migration run
public function up(): void
{
$number_of_unmigrated = $this->get_count_of_unmigrated();
error_log("Migrating sales tax history. The number of sales that will be migrated is $number_of_unmigrated"); //TODO: String interpolation
error_log("Migrating sales tax history. The number of sales that will be migrated is $number_of_unmigrated");
if($number_of_unmigrated > 0)
{
$unmigrated_invoices = $this->get_unmigrated($number_of_unmigrated)->getResultArray();
foreach($unmigrated_invoices as $key => $unmigrated_invoice)
{
$this->upgrade_tax_history_for_sale($unmigrated_invoice['sale_id']);
@@ -335,4 +332,4 @@ class Migration_Sales_Tax_Data extends Migration
$sales_taxes[$row_number]['sale_tax_amount'] = $rounded_sale_tax_amount;
}
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_Upgrade_To_3_2_0 extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.1.1_to_3.2.0.sql');
}
@@ -15,4 +16,4 @@ class Migration_Upgrade_To_3_2_0 extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_Upgrade_To_3_2_1 extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.2.0_to_3.2.1.sql');
}
@@ -15,4 +16,4 @@ class Migration_Upgrade_To_3_2_1 extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_Attributes extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_attributes.sql');
}
@@ -15,4 +16,4 @@ class Migration_Attributes extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_Upgrade_To_3_3_0 extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.2.1_to_3.3.0.sql');
}
@@ -15,4 +16,4 @@ class Migration_Upgrade_To_3_3_0 extends Migration
{
}
}
}

View File

@@ -14,6 +14,7 @@ class Migration_IndiaGST extends Migration
}
// If number of entries is greater than zero then the tax data needs to be migrated
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_indiagst.sql');
error_log('Migrating tax configuration');
@@ -145,4 +146,4 @@ class Migration_IndiaGST extends Migration
$this->db->query('DROP TABLE IF EXISTS ' . $this->db->prefixTable('sales_taxes_backup'));
$this->db->query('DROP TABLE IF EXISTS ' . $this->db->prefixTable('tax_code_rates_backup'));
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_IndiaGST1 extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_indiagst1.sql');
error_log('Fix definition of Supplier.Tax Id');
@@ -19,4 +20,4 @@ class Migration_IndiaGST1 extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_IndiaGST2 extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_indiagst2.sql');
}
@@ -15,4 +16,4 @@ class Migration_IndiaGST2 extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_decimal_attribute_type extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_decimal_attribute_type.sql');
}
@@ -15,4 +16,4 @@ class Migration_decimal_attribute_type extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_add_iso_4217 extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_add_iso_4217.sql');
}
@@ -15,4 +16,4 @@ class Migration_add_iso_4217 extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_PaymentTracking extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_paymenttracking.sql');
}
@@ -15,4 +16,4 @@ class Migration_PaymentTracking extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_RefundTracking extends Migration
{
public function up(): void
{
helper(['migration', 'locale']);
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_refundtracking.sql');
// Add missing cash_refund amounts to payments table
@@ -103,4 +104,4 @@ class Migration_RefundTracking extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_DBFix extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_dbfix.sql');
}
@@ -15,4 +16,4 @@ class Migration_DBFix extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_fix_attribute_datetime extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_fix_attribute_datetime.sql');
}
@@ -15,4 +16,4 @@ class Migration_fix_attribute_datetime extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_PaymentDateFix extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.2_paymentdatefix.sql');
}
@@ -15,4 +16,4 @@ class Migration_PaymentDateFix extends Migration
{
}
}
}

View File

@@ -8,6 +8,7 @@ class Migration_SalesChangePrice extends Migration
{
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.2_saleschangeprice.sql');
}
@@ -15,4 +16,4 @@ class Migration_SalesChangePrice extends Migration
{
}
}
}

View File

@@ -27,7 +27,6 @@ class Migration_TaxAmount extends Migration
parent::__construct();
$this->appconfig = model('Appconfig');
$this->tax_lib = new Tax_lib();
}
public function up(): void
@@ -314,4 +313,4 @@ class Migration_TaxAmount extends Migration
$sales_taxes[$row_number]['sale_tax_amount'] = $rounded_sale_tax_amount;
}
}
}
}

View File

@@ -10,7 +10,7 @@ class Migration_modify_attr_links_constraint extends Migration
{
error_log('Migrating modify_attr_links_constraint');
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.2_modify_attr_links_constraint.sql');
error_log('Migrating modify_attr_links_constraint');
@@ -19,4 +19,4 @@ class Migration_modify_attr_links_constraint extends Migration
public function down(): void
{
}
}
}

View File

@@ -10,6 +10,7 @@ class Migration_add_item_kit_number extends Migration
{
error_log('Migrating add_item_kit_number');
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.3_add_kits_item_number.sql');
error_log('Migrating add_item_kit_number');
@@ -18,4 +19,4 @@ class Migration_add_item_kit_number extends Migration
public function down(): void
{
}
}
}

View File

@@ -10,6 +10,7 @@ class Migration_modify_session_datatype extends Migration
{
error_log('Migrating modify_session_datatype');
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.4_modify_session_datatype.sql');
error_log('Migrating modify_session_datatype');
@@ -18,4 +19,4 @@ class Migration_modify_session_datatype extends Migration
public function down(): void
{
}
}
}

View File

@@ -72,6 +72,7 @@ class Migration_database_optimizations extends Migration
}
$this->db->transComplete();
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.4.0_database_optimizations.sql');
error_log('Migrating database_optimizations completed');
}
@@ -130,4 +131,4 @@ class Migration_database_optimizations extends Migration
public function down(): void
{
}
}
}

View File

@@ -10,6 +10,7 @@ class Convert_to_ci4 extends Migration
{
error_log('Migrating database to CodeIgniter4 formats');
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.4.0_ci4_conversion.sql');
error_log('Migrating to CodeIgniter4 formats completed');

View File

@@ -14,9 +14,14 @@ class MY_Migration extends MigrationRunner
public function get_current_version(): string
{
$builder = $this->db->table('migrations');
$builder->select('version');
return $builder->get()->getRow()->version;
if($this->db->tableExists('migrations'))
{
$builder = $this->db->table('migrations');
$builder->select('version');
return $builder->get()->getRow()->version;
}
return 0;
}
public function is_latest(): bool

View File

@@ -10,7 +10,7 @@ use App\Models\Tax;
use App\Models\Tax_category;
use App\Models\Tax_code;
use App\Models\Tax_jurisdiction;
use App\Libraries\Sale_lib;
/**
* Tax library
@@ -498,4 +498,4 @@ class Tax_lib
return '<option value=\"' . Tax_lib::TAX_TYPE_EXCLUDED . '\" ' . $s1 . '> ' . lang('Taxes.sales_tax'). '</option>'
. '<option value=\"' . Tax_lib::TAX_TYPE_INCLUDED . '\" ' . $s2 . '> ' . lang('Taxes.vat_tax') . '</option>';
}
}
}

View File

@@ -32,7 +32,7 @@ class Appconfig extends Model
public function get_value(string $key, string $default = ''): string
{
$builder = $this->db->table('app_config');
$query = $builder->getWhere('key', $key, 1);
$query = $builder->getWhere(['key' => $key], 1, 1);
if($query->getNumRows() == 1) //TODO: ===
{
@@ -141,4 +141,4 @@ class Appconfig extends Model
return $last_used;
}
}
}

View File

@@ -3,6 +3,7 @@
* @var bool $has_errors
* @var bool $is_latest
* @var string $latest_version
* @var bool $gcaptcha_enabled
*/
?>
@@ -84,7 +85,7 @@
</div>
<?php endif; ?>
<?php if(config('OSPOS')->settings['gcaptcha_enable'])
<?php if($gcaptcha_enabled)
{
echo '<script src="https://www.google.com/recaptcha/api.js"></script>';
echo '<div class="g-recaptcha mb-3" style="text-align: center;" data-sitekey="' . config('OSPOS')->settings['gcaptcha_site_key'] . '"></div>';