<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251022183255 extends AbstractMigration
{
// shared-sales-stats (old, to be replaced)
public const OLD_WIDGET_ID = 36;
// New widgets
public const WIDGET_ID_1 = 38; // shared-sales-ranking
public const WIDGET_ID_2 = 39; // shared-sales-customers
public const WIDGET_ID_3 = 40; // shared-sales-fees
public const WIDGET_ID_4 = 41; // shared-sales-cash
public const WIDGET_ID_5 = 42; // shared-sales-new-leads
public const WIDGET_ID_6 = 43; // shared-sales-new-opportunities
public const WIDGET_ID_7 = 44; // shared-unread-messages
public const WIDGET_ID_8 = 45; // shared-unread-feeds
public const WIDGET_ID_9 = 46; // shared-unread-streams
public const WIDGET_ID_10 = 47; // shared-unread-projects
public const WIDGET_ID_11 = 48; // shared-open-issues
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
foreach (self::newWidgets() as [$id, $token, $name]) {
$this->addSql(
'INSERT INTO widget (id, token, name, category, enabled) VALUES (?, ?, ?, ?, 1)',
[$id, $token, $name, 'Shared']
);
}
/** @#var string $idList */
$idList = $this->idListSql(self::newWidgetIds());
$this->addSql(sprintf(
'
INSERT INTO user_widget (object_id, widget_id)
SELECT uw.object_id, w.id
FROM user_widget uw
JOIN widget w ON w.id IN (%s)
WHERE uw.widget_id = %d
',
$idList,
self::OLD_WIDGET_ID
));
$this->addSql(sprintf('DELETE FROM widget WHERE id = %d', self::OLD_WIDGET_ID));
$this->addSql(sprintf('DELETE FROM user_widget WHERE widget_id = %d', self::OLD_WIDGET_ID));
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(sprintf('INSERT INTO widget (id, token, name, category, enabled) VALUES (%d, \'shared-sales-stats\', \'Sales Stats\', \'Shared\', 1)', self::OLD_WIDGET_ID));
/** @#var string $idList */
$idList = $this->idListSql(self::newWidgetIds());
$this->addSql(sprintf(
'
INSERT INTO user_widget (object_id, widget_id)
SELECT DISTINCT object_id, %d
FROM user_widget
WHERE widget_id IN (%s)
',
self::OLD_WIDGET_ID,
$idList
));
$this->addSql(sprintf('DELETE FROM widget WHERE id in (%s)', $idList));
$this->addSql(sprintf('DELETE FROM user_widget WHERE widget_id in (%s)', $idList));
}
/**
* @return array
*/
private static function newWidgetIds(): array
{
return [
self::WIDGET_ID_1,
self::WIDGET_ID_2,
self::WIDGET_ID_3,
self::WIDGET_ID_4,
self::WIDGET_ID_5,
self::WIDGET_ID_6,
self::WIDGET_ID_7,
self::WIDGET_ID_8,
self::WIDGET_ID_9,
self::WIDGET_ID_10,
self::WIDGET_ID_11,
];
}
/**
* @return array
*/
private static function newWidgets(): array
{
return [
[self::WIDGET_ID_1, 'shared-sales-ranking', 'Sales Ranking'],
[self::WIDGET_ID_2, 'shared-sales-customers', 'Sales Customers'],
[self::WIDGET_ID_3, 'shared-sales-fees', 'Sales Fees'],
[self::WIDGET_ID_4, 'shared-sales-cash', 'Sales Cash'],
[self::WIDGET_ID_5, 'shared-sales-new-leads', 'Sales New Leads'],
[self::WIDGET_ID_6, 'shared-sales-new-opportunities', 'Sales New Opportunities'],
[self::WIDGET_ID_7, 'shared-unread-messages', 'Sales Unread Messages'],
[self::WIDGET_ID_8, 'shared-unread-feeds', 'Sales Unread Feeds'],
[self::WIDGET_ID_9, 'shared-unread-streams', 'Sales Unread Streams'],
[self::WIDGET_ID_10, 'shared-unread-projects', 'Sales Unread Projects'],
[self::WIDGET_ID_11, 'shared-open-issues', 'Sales Open Tickets'],
];
}
/**
* @param array $ids
*
* @return string
*/
private function idListSql(array $ids): string
{
return implode(',', array_map('intval', $ids));
}
}