Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

#### 🐛 Исправлено

**Двойной префикс в Phinx defensive-checks из PR #271 (#276):**
- `TablePrefixAdapter::hasTable($name)` / `$this->table($name)` / `hasColumn` сами добавляют `table_prefix`. Ручной конкат `$prefix . 'ms3_grid_fields'` в defensive-проверках после #271 приводил к двойному префиксу (`modx_modx_*`) — Phinx никогда не находил таблицу и seed-миграции всегда уходили в no-op.
- **Воздействие**: на свежих установках MS3 ≥ 1.10.1 таблица `ms3_grid_fields` создавалась, но не наполнялась — гриды (заказы, клиенты, доставки, оплаты, вендоры, позиции заказа, товары категории) загружались без default-конфигурации. На существующих установках, где seed успел выполниться до #271, последствий нет.
- **Затронуты** все 9 seed/fix-миграций после #271 + `initial_schema` (метод `addForeignKeys()` — FK constraints из-за того же бага никогда не создавались на свежих установках).
- В Phinx API-методах теперь передаём UNPREFIXED имя; raw SQL через `$this->execute()` / `fetchAll()` по-прежнему получает `{$prefix}name` (он не префиксируется автоматически).

**Отрицательный итог заказа; бейджи «Скидка / Наценка» во Vue менеджере (#265):**
- `OrderService::clampComputedTotal()` при сумме меньше нуля ограничивает итог нулём и записывает в журнал MODX предупреждение с разбивкой `cart_cost`, `delivery_cost`, `payment_cost`.
- Вызов защиты добавлен при расчёте стоимости в `OrderCostCalculator`, пересчёте черновика (`OrderDraftManager`), финализации заказа (`OrderFinalizeService`), пересчёте сумм менеджерского API и при `OrderService::updateProducts()`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ protected function addForeignKeys()
{
$this->output->writeln('<info>Adding foreign key constraints...</info>');

$prefix = $this->adapter->getOption('table_prefix');

// Phinx API (hasTable / $this->table / addForeignKey target) auto-prefixes
// table names — pass UNPREFIXED. The previous code prepended $prefix manually,
// resulting in double-prefixed lookups (modx_modx_*) which silently never matched,
// so FK constraints were never created. Same bug fix as #276 for seed-migrations.
// msProductField.section -> msPageSection.id
if ($this->hasTable($prefix . 'ms3_product_fields') && $this->hasTable($prefix . 'ms3_page_sections')) {
if ($this->hasTable('ms3_product_fields') && $this->hasTable('ms3_page_sections')) {
try {
$table = $this->table($prefix . 'ms3_product_fields');
$table->addForeignKey('section', $prefix . 'ms3_page_sections', 'id', [
$table = $this->table('ms3_product_fields');
$table->addForeignKey('section', 'ms3_page_sections', 'id', [
'delete' => 'RESTRICT',
'update' => 'CASCADE',
'constraint' => 'fk_product_fields_section',
Expand All @@ -158,19 +160,22 @@ public function down()
$prefix = $this->adapter->getOption('table_prefix');

foreach ($this->modelClasses as $className) {
$tableName = $prefix . 'ms3_' . $this->camelToSnake($className);
// Unprefixed name for Phinx API; prefixed FQN only for logging.
$tableName = 'ms3_' . $this->camelToSnake($className);
$tableFqn = $prefix . $tableName;

if ($this->hasTable($tableName)) {
$this->table($tableName)->drop()->save();
$this->output->writeln("<info> ✓ Dropped table: {$tableName}</info>");
$this->output->writeln("<info> ✓ Dropped table: {$tableFqn}</info>");
}
}

// Drop migrations table
$migrationsTable = $prefix . 'ms3_migrations';
$migrationsTable = 'ms3_migrations';
$migrationsTableFqn = $prefix . $migrationsTable;
if ($this->hasTable($migrationsTable)) {
$this->table($migrationsTable)->drop()->save();
$this->output->writeln("<info> ✓ Dropped migrations table: {$migrationsTable}</info>");
$this->output->writeln("<info> ✓ Dropped migrations table: {$migrationsTableFqn}</info>");
}

$this->output->writeln('<info>MiniShop3 schema removal completed!</info>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function up()
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: ensure table exists (initial schema may not have run yet)
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping customers grid seed</comment>');
return;
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public function up()
public function down()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}
$this->execute("DELETE FROM {$prefix}ms3_grid_fields WHERE grid_key = 'customers'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function up()
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: ensure table exists
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping orders grid seed</comment>');
return;
}
Expand Down Expand Up @@ -335,7 +335,7 @@ public function up()
public function down()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}
$this->execute("DELETE FROM {$prefix}ms3_grid_fields WHERE grid_key = 'orders'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: ensure table exists
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping order_products grid seed</comment>');
return;
}
Expand Down Expand Up @@ -258,7 +258,7 @@ public function up()
public function down()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}
$this->execute("DELETE FROM {$prefix}ms3_grid_fields WHERE grid_key = 'order_products'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function up()
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: ensure table exists
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping deliveries grid seed</comment>');
return;
}
Expand Down Expand Up @@ -216,7 +216,7 @@ public function up()
public function down()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}
$this->execute("DELETE FROM {$prefix}ms3_grid_fields WHERE grid_key = 'deliveries'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function up()
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: ensure table exists
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping vendors grid seed</comment>');
return;
}
Expand Down Expand Up @@ -233,7 +233,7 @@ public function up()
public function down()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}
$this->execute("DELETE FROM {$prefix}ms3_grid_fields WHERE grid_key = 'vendors'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function up()
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: ensure table exists
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping category-products grid seed</comment>');
return;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public function up()
public function down()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
if (!$this->hasTable($prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}
$this->execute("DELETE FROM {$prefix}ms3_grid_fields WHERE grid_key = 'category-products'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class FixOrdersGridFilterable extends AbstractMigration
public function up()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
$table = $prefix . 'ms3_grid_fields';
$table = $prefix . 'ms3_grid_fields'; // raw-SQL FQN

// Defensive: skip if table doesn't exist
if (!$this->hasTable($table)) {
// Defensive: skip if table doesn't exist. Phinx API auto-prefixes — pass unprefixed name.
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping</comment>');
return;
}
Expand All @@ -37,10 +37,10 @@ public function up()
public function down()
{
$prefix = $this->getAdapter()->getOption('table_prefix') ?? '';
$table = $prefix . 'ms3_grid_fields';
$table = $prefix . 'ms3_grid_fields'; // raw-SQL FQN

// Defensive: skip if table doesn't exist
if (!$this->hasTable($table)) {
// Defensive: skip if table doesn't exist. Phinx API auto-prefixes — pass unprefixed name.
if (!$this->hasTable('ms3_grid_fields')) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function up(): void
$this->prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: ensure table exists
if (!$this->hasTable($this->prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping</comment>');
return;
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public function down(): void
$this->prefix = $this->getAdapter()->getOption('table_prefix') ?? '';

// Defensive: skip if table doesn't exist
if (!$this->hasTable($this->prefix . 'ms3_grid_fields')) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function up(): void
$table = $this->prefix . 'ms3_grid_fields';

// Defensive: skip if table doesn't exist
if (!$this->hasTable($table)) {
if (!$this->hasTable('ms3_grid_fields')) {
$this->output->writeln('<comment>Table ms3_grid_fields does not exist, skipping</comment>');
return;
}
Expand Down Expand Up @@ -70,7 +70,7 @@ public function down(): void
$table = $this->prefix . 'ms3_grid_fields';

// Defensive: skip if table doesn't exist
if (!$this->hasTable($table)) {
if (!$this->hasTable('ms3_grid_fields')) {
return;
}

Expand Down