-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix comparing reviews not working on specific multi-site setups
- Loading branch information
1 parent
e63c803
commit 4e9d34d
Showing
6 changed files
with
66 additions
and
3 deletions.
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,56 @@ | ||
<?php | ||
namespace verbb\workflow\migrations; | ||
|
||
use craft\db\Migration; | ||
use craft\db\Query; | ||
|
||
use Throwable; | ||
|
||
class m231112_000000_reviews_siteid extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
if (!$this->db->columnExists('{{%workflow_reviews}}', 'elementSiteId')) { | ||
$this->addColumn('{{%workflow_reviews}}', 'elementSiteId', $this->integer()->after('elementId')); | ||
} | ||
|
||
$this->createIndex(null, '{{%workflow_reviews}}', 'elementSiteId', false); | ||
$this->addForeignKey(null, '{{%workflow_reviews}}', 'elementSiteId', '{{%sites}}', 'id', 'CASCADE', null); | ||
|
||
// Populate the site info from submissions | ||
$submissions = (new Query()) | ||
->select(['id', 'ownerSiteId']) | ||
->from(['{{%workflow_submissions}}']) | ||
->indexBy('id') | ||
->all(); | ||
|
||
$reviews = (new Query()) | ||
->select(['*']) | ||
->from(['{{%workflow_reviews}}']) | ||
->all(); | ||
|
||
foreach ($reviews as $review) { | ||
$submissionId = $review['submissionId'] ?? null; | ||
|
||
if ($submissionId) { | ||
$this->update('{{%workflow_reviews}}', [ | ||
'elementSiteId' => $submissions[$submissionId]['ownerSiteId'] ?? null, | ||
], ['id' => $review['id']]); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m231112_000000_reviews_siteid cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |
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