Skip to content

Commit

Permalink
Fix optionsSignature error when updating
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Oct 5, 2020
1 parent 2feafcd commit dc109f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 37 deletions.
20 changes: 19 additions & 1 deletion src/migrations/m201003_000000_add_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use Craft;
use craft\db\Migration;
use craft\db\Query;
use craft\helpers\Json;
use craft\queue\jobs\ResaveElements;

class m201003_000000_add_options extends Migration
Expand All @@ -16,7 +18,23 @@ public function safeUp()
}

if (!$this->db->columnExists('{{%wishlist_items}}', 'optionsSignature')) {
$this->addColumn('{{%wishlist_items}}', 'optionsSignature', $this->string()->notNull()->after('options'));
$this->addColumn('{{%wishlist_items}}', 'optionsSignature', $this->string()->after('options'));

// Populate the values
$items = (new Query())
->select(['*'])
->from(['{{%wishlist_items}} items'])
->all();

foreach ($items as $key => $item) {
$this->update('{{%wishlist_items}}', [
'options' => Json::encode([]),
'optionsSignature' => md5(Json::encode([]))
], ['id' => $item['id']]);
}

// Mark the column as not null, now values have been imported
$this->alterColumn('{{%wishlist_items}}', 'optionsSignature', $this->string()->notNull());
}

return true;
Expand Down
36 changes: 0 additions & 36 deletions src/migrations/m201004_000000_generate_options.php

This file was deleted.

0 comments on commit dc109f1

Please sign in to comment.