-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
294c216
commit ce1687b
Showing
19 changed files
with
420 additions
and
41 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
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
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
63 changes: 63 additions & 0 deletions
63
src/migrations/m240117_112821_create_activity_logs_table.php
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,63 @@ | ||
<?php | ||
|
||
namespace acclaro\translations\migrations; | ||
|
||
use acclaro\translations\Constants; | ||
use craft\db\Migration; | ||
|
||
/** | ||
* Combined migration for dropping activityLog column and creating activity_log table. | ||
*/ | ||
class m240117_112821_create_activity_logs_table extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
// Create activity_log table | ||
$this->createTable(Constants::TABLE_ACTIVITY_LOG, [ | ||
'id' => $this->primaryKey(), | ||
'targetId' => $this->integer()->notNull(), | ||
'targetClass' => $this->string()->notNull(), | ||
'created' => $this->dateTime()->notNull(), | ||
'message' => $this->text(), | ||
'actions' => $this->text() | ||
]); | ||
|
||
$this->createIndex(null, Constants::TABLE_ACTIVITY_LOG, ['targetId']); | ||
$this->createIndex(null, Constants::TABLE_ACTIVITY_LOG, ['targetClass']); | ||
|
||
// Move data from activityLog column to activity_log table | ||
$data = $this->db->createCommand('SELECT id, activityLog FROM {{%translations_orders}}')->queryAll(); | ||
|
||
foreach ($data as $row) { | ||
$messages = json_decode($row['activityLog'], true); | ||
|
||
foreach ($messages as $message) { | ||
// Insert data into activity_log table | ||
$this->insert(Constants::TABLE_ACTIVITY_LOG, [ | ||
'created' => \DateTime::createFromFormat('d/m/Y', $message['date'])->format('Y-m-d H:i:s'), | ||
'targetId' => $row['id'], | ||
'targetClass' => 'acclaro\\translations\\elements\\Order', | ||
'message' => $message['message'], | ||
'actions' => '' | ||
]); | ||
} | ||
} | ||
|
||
// Drop activityLog column | ||
$this->dropColumn(Constants::TABLE_ORDERS, 'activityLog'); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m240117_054435_create_activity_log cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |
Oops, something went wrong.