-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace craft\commerce\migrations; | ||
|
||
use Craft; | ||
use craft\commerce\helpers\Purchasable; | ||
use craft\db\Migration; | ||
|
||
/** | ||
* m241017_072151_fix_temp_skus migration. | ||
*/ | ||
class m241017_072151_fix_temp_skus extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
// get any sku that starts with __temp_ in the purchasables table, loop over them and replace with a new SKU | ||
$purchasables = (new \craft\db\Query()) | ||
->select(['id', 'sku']) | ||
->from('{{%commerce_purchasables}}') | ||
->where(['like', 'sku', '__temp_%', false]) | ||
->all(); | ||
|
||
// Need a unique one per purchasable | ||
foreach ($purchasables as $purchasable) { | ||
$newSku = Purchasable::tempSku(); | ||
$this->update('{{%commerce_purchasables}}', ['sku' => $newSku], ['id' => $purchasable['id']]); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m241017_072151_fix_temp_skus cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |