migrations/Version20180809165311.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\DBAL\Types\AccessRoleType;
  5. use App\Entity\User;
  6. use Doctrine\DBAL\Schema\Schema;
  7. use Doctrine\Migrations\AbstractMigration;
  8. use EWZ\SymfonyAdminBundle\Util\StringUtil;
  9. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  12. use Symfony\Component\String\Slugger\AsciiSlugger;
  13. /**
  14.  * Auto-generated Migration: Please modify to your needs!
  15.  */
  16. final class Version20180809165311 extends AbstractMigration implements ContainerAwareInterface
  17. {
  18.     /** @var ContainerInterface */
  19.     private $container;
  20.     /**
  21.      * @param ContainerInterface|null $container
  22.      */
  23.     public function setContainer(ContainerInterface $container null)
  24.     {
  25.         $this->container $container;
  26.     }
  27.     public function up(Schema $schema): void
  28.     {
  29.         // this up() migration is auto-generated, please modify it to your needs
  30.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  31.         $this->addSql('DROP TABLE administrators_favorites');
  32.         $this->addSql('RENAME TABLE administrators_teams TO user_team');
  33.         $this->addSql('ALTER TABLE user_team ENGINE = InnoDB');
  34.         $this->addSql('ALTER TABLE user_team CHARACTER SET = utf8mb4');
  35.         $this->addSql('
  36.             ALTER TABLE user_team
  37.                 DROP type,
  38.                 CHANGE name name VARCHAR(255) NOT NULL
  39.         ');
  40.         $this->addSql('
  41.             CREATE TABLE user_report (
  42.                 object_id INT NOT NULL,
  43.                 report_id INT NOT NULL,
  44.                 INDEX IDX_A17D6CB9232D562B (object_id),
  45.                 INDEX IDX_A17D6CB94BD2A4C0 (report_id),
  46.                 PRIMARY KEY(object_id, report_id)
  47.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  48.         ');
  49.         $this->addSql('
  50.             CREATE TABLE group_report (
  51.                 object_id INT NOT NULL,
  52.                 report_id INT NOT NULL,
  53.                 INDEX IDX_17A9AF54232D562B (object_id),
  54.                 INDEX IDX_17A9AF544BD2A4C0 (report_id),
  55.                 PRIMARY KEY(object_id, report_id)
  56.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  57.         ');
  58.         $this->addSql('
  59.             CREATE TABLE report (
  60.                 id INT AUTO_INCREMENT NOT NULL,
  61.                 token VARCHAR(255) NOT NULL,
  62.                 name VARCHAR(255) NOT NULL,
  63.                 category VARCHAR(255) NOT NULL,
  64.                 enabled TINYINT(1) NOT NULL,
  65.                 INDEX idx_token (token),
  66.                 INDEX idx_name (name),
  67.                 PRIMARY KEY(id)
  68.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  69.         ');
  70.         foreach ($this->getReports() as $key => $value) {
  71.             $id = (int) (array_search($keyarray_keys($this->getReports()))) + 1;
  72.             $slugger = new AsciiSlugger();
  73.             $token $slugger->slug(sprintf('%s_%s'$value['category'], $value['name']));
  74.             $this->addSql('INSERT INTO report (id, token, name, category, enabled) VALUES (:id, :token, :name, :category, 1)', [
  75.                 'id' => $id,
  76.                 'token' => $token,
  77.                 'name' => $value['name'],
  78.                 'category' => $value['category'],
  79.             ]);
  80.         }
  81.         $this->addSql('
  82.             CREATE TABLE user_widget (
  83.                 object_id INT NOT NULL,
  84.                 widget_id INT NOT NULL,
  85.                 INDEX IDX_E0AB05ED232D562B (object_id),
  86.                 INDEX IDX_E0AB05EDFBE885E2 (widget_id),
  87.                 PRIMARY KEY(object_id, widget_id)
  88.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  89.         ');
  90.         $this->addSql('
  91.             CREATE TABLE group_widget (
  92.                 object_id INT NOT NULL,
  93.                 widget_id INT NOT NULL,
  94.                 INDEX IDX_567FC600232D562B (object_id),
  95.                 INDEX IDX_567FC600FBE885E2 (widget_id),
  96.                 PRIMARY KEY(object_id, widget_id)
  97.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  98.         ');
  99.         $this->addSql('
  100.             CREATE TABLE widget (
  101.                 id INT AUTO_INCREMENT NOT NULL,
  102.                 token VARCHAR(255) NOT NULL,
  103.                 name VARCHAR(255) NOT NULL,
  104.                 category VARCHAR(255) NOT NULL,
  105.                 enabled TINYINT(1) NOT NULL,
  106.                 INDEX idx_token (token),
  107.                 INDEX idx_name (name),
  108.                 PRIMARY KEY(id)
  109.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  110.         ');
  111.         foreach ($this->getWidgets() as $key => $value) {
  112.             $id = (int) (array_search($keyarray_keys($this->getWidgets()))) + 1;
  113.             $slugger = new AsciiSlugger();
  114.             $token $slugger->slug(sprintf('%s_%s'$value['category'], $value['name']));
  115.             $this->addSql('INSERT INTO widget (id, token, name, category, enabled) VALUES (:id, :token, :name, :category, 1)', [
  116.                 'id' => $id,
  117.                 'token' => $token,
  118.                 'name' => $value['name'],
  119.                 'category' => $value['category'],
  120.             ]);
  121.         }
  122.         $this->addSql('
  123.             ALTER TABLE administrators_groups
  124.                 ADD access_customer_entity TINYINT(1) NOT NULL,
  125.                 ADD access_customer_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  126.                 ADD access_lead_entity TINYINT(1) NOT NULL,
  127.                 ADD access_lead_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  128.                 ADD access_event_entity TINYINT(1) NOT NULL,
  129.                 ADD access_event_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  130.                 ADD access_feed_entity TINYINT(1) NOT NULL,
  131.                 ADD access_feed_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  132.                 ADD access_issue_entity TINYINT(1) NOT NULL,
  133.                 ADD access_issue_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  134.                 ADD access_message_entity TINYINT(1) NOT NULL,
  135.                 ADD access_message_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  136.                 ADD access_all_reports TINYINT(1) NOT NULL,
  137.                 ADD access_all_widgets TINYINT(1) NOT NULL
  138.         ');
  139.         $stmt $this->connection->prepare('SELECT * FROM administrators_groups');
  140.         $stmt->execute();
  141.         while ($row $stmt->fetch(\PDO::FETCH_OBJ)) {
  142.             $reports $row->reports explode(','$row->reports) : [];
  143.             $widgets $row->dashboard explode(','$row->dashboard) : [];
  144.             $permissions $row->permissions json_decode($row->permissionstrue) : [];
  145.             $accessCustomerEntityRoles = [];
  146.             $accessLeadEntityRoles = [];
  147.             $accessEventEntityRoles = [];
  148.             if (\array_key_exists('customers'$permissions)) {
  149.                 if (\in_array('new'$permissions['customers'])) {
  150.                     $accessCustomerEntityRoles[] = AccessRoleType::CREATE;
  151.                 }
  152.                 if (\in_array('edit'$permissions['customers'])) {
  153.                     $accessCustomerEntityRoles[] = AccessRoleType::EDIT;
  154.                 }
  155.                 if (\in_array('delete'$permissions['customers'])) {
  156.                     $accessCustomerEntityRoles[] = AccessRoleType::DELETE;
  157.                 }
  158.             }
  159.             if (\array_key_exists('leads'$permissions)) {
  160.                 if (\in_array('new'$permissions['leads'])) {
  161.                     $accessLeadEntityRoles[] = AccessRoleType::CREATE;
  162.                 }
  163.                 if (\in_array('edit'$permissions['leads'])) {
  164.                     $accessLeadEntityRoles[] = AccessRoleType::EDIT;
  165.                 }
  166.                 if (\in_array('delete'$permissions['leads'])) {
  167.                     $accessLeadEntityRoles[] = AccessRoleType::DELETE;
  168.                 }
  169.             }
  170.             if (\array_key_exists('events'$permissions)) {
  171.                 if (\in_array('new'$permissions['events'])) {
  172.                     $accessEventEntityRoles[] = AccessRoleType::CREATE;
  173.                 }
  174.                 if (\in_array('edit'$permissions['events'])) {
  175.                     $accessEventEntityRoles[] = AccessRoleType::EDIT;
  176.                 }
  177.                 if (\in_array('delete'$permissions['events'])) {
  178.                     $accessEventEntityRoles[] = AccessRoleType::DELETE;
  179.                 }
  180.             }
  181.             if (\array_key_exists('*'$permissions)) {
  182.                 $accessCustomerEntityRoles = [
  183.                     AccessRoleType::CREATE,
  184.                     AccessRoleType::EDIT,
  185.                     AccessRoleType::DELETE,
  186.                 ];
  187.                 $accessLeadEntityRoles = [
  188.                     AccessRoleType::CREATE,
  189.                     AccessRoleType::EDIT,
  190.                     AccessRoleType::DELETE,
  191.                 ];
  192.                 $accessEventEntityRoles = [
  193.                     AccessRoleType::CREATE,
  194.                     AccessRoleType::EDIT,
  195.                     AccessRoleType::DELETE,
  196.                 ];
  197.             }
  198.             if (empty($accessCustomerEntityRoles)) {
  199.                 $accessCustomerEntityRoles null;
  200.             }
  201.             if (empty($accessLeadEntityRoles)) {
  202.                 $accessLeadEntityRoles null;
  203.             }
  204.             if (empty($accessEventEntityRoles)) {
  205.                 $accessEventEntityRoles null;
  206.             }
  207.             $this->addSql('UPDATE administrators_groups SET access_all_reports = :access_all_reports, access_all_widgets = :access_all_widgets, access_customer_entity = :access_customer_entity, access_customer_entity_role = :access_customer_entity_role, access_lead_entity = :access_lead_entity, access_lead_entity_role = :access_lead_entity_role, access_event_entity = :access_event_entity, access_event_entity_role = :access_event_entity_role, access_feed_entity = :access_feed_entity, access_feed_entity_role = :access_feed_entity_role, access_issue_entity = :access_issue_entity, access_issue_entity_role = :access_issue_entity_role, access_message_entity = :access_message_entity, access_message_entity_role = :access_message_entity_role WHERE id = :id', [
  208.                 'id' => $row->id,
  209.                 'access_all_reports' => (int) \in_array('*'$reports),
  210.                 'access_all_widgets' => (int) \in_array('*'$reports),
  211.                 'access_customer_entity' => (int) (\array_key_exists('*'$permissions) || \array_key_exists('customers'$permissions)),
  212.                 'access_customer_entity_role' => $accessCustomerEntityRoles serialize($accessCustomerEntityRoles) : null,
  213.                 'access_lead_entity' => (int) (\array_key_exists('*'$permissions) || \array_key_exists('leads'$permissions)),
  214.                 'access_lead_entity_role' => $accessLeadEntityRoles serialize($accessLeadEntityRoles) : null,
  215.                 'access_event_entity' => (int) (\array_key_exists('*'$permissions) || \array_key_exists('events'$permissions)),
  216.                 'access_event_entity_role' => $accessEventEntityRoles serialize($accessEventEntityRoles) : null,
  217.                 'access_feed_entity' => true,
  218.                 'access_feed_entity_role' => serialize([
  219.                     AccessRoleType::CREATE,
  220.                     AccessRoleType::EDIT,
  221.                     AccessRoleType::DELETE,
  222.                 ]),
  223.                 'access_issue_entity' => true,
  224.                 'access_issue_entity_role' => serialize([
  225.                     AccessRoleType::CREATE,
  226.                     AccessRoleType::EDIT,
  227.                     AccessRoleType::DELETE,
  228.                 ]),
  229.                 'access_message_entity' => true,
  230.                 'access_message_entity_role' => serialize([
  231.                     AccessRoleType::CREATE,
  232.                     AccessRoleType::EDIT,
  233.                     AccessRoleType::DELETE,
  234.                 ]),
  235.             ]);
  236.             if (!empty($reports)) {
  237.                 $reports array_unique($reports);
  238.                 foreach ($reports as $report) {
  239.                     if ($report && '*' !== $report && \array_key_exists($report$this->getReports())) {
  240.                         $report = (int) (array_search($reportarray_keys($this->getReports()))) + 1;
  241.                         $this->addSql('INSERT INTO group_report (object_id, report_id) values (:object_id, :report_id)', [
  242.                             'object_id' => $row->id,
  243.                             'report_id' => $report,
  244.                         ]);
  245.                     }
  246.                 }
  247.             }
  248.             if (!empty($widgets)) {
  249.                 $widgets array_unique($widgets);
  250.                 foreach ($widgets as $widget) {
  251.                     if ($widget && '*' !== $widget) {
  252.                         $tmp = [];
  253.                         if (\array_key_exists($widget$this->getWidgets())) {
  254.                             $tmp[] = $widget;
  255.                         } else {
  256.                             foreach ($this->getWidgets() as $key => $value) {
  257.                                 $legacy $value['legacy'] ?? [];
  258.                                 if (!\is_array($legacy)) {
  259.                                     $legacy = [$legacy];
  260.                                 }
  261.                                 if (\in_array($widget$legacy)) {
  262.                                     $tmp[] = $key;
  263.                                 }
  264.                             }
  265.                         }
  266.                         foreach ($tmp as $widget) {
  267.                             $widget = (int) (array_search($widgetarray_keys($this->getWidgets()))) + 1;
  268.                             $this->addSql('INSERT IGNORE INTO group_widget (object_id, widget_id) values (:object_id, :widget_id)', [
  269.                                 'object_id' => $row->id,
  270.                                 'widget_id' => $widget,
  271.                             ]);
  272.                         }
  273.                     }
  274.                 }
  275.             }
  276.         }
  277.         $this->addSql('RENAME TABLE administrators_groups TO user_group');
  278.         $this->addSql('ALTER TABLE user_group ENGINE = InnoDB');
  279.         $this->addSql('ALTER TABLE user_group CHARACTER SET = utf8mb4');
  280.         $this->addSql('
  281.             ALTER TABLE user_group
  282.                 DROP permissions,
  283.                 DROP reports,
  284.                 DROP dashboard,
  285.                 CHANGE name name VARCHAR(255) NOT NULL
  286.         ');
  287.         $this->addSql('
  288.             CREATE TABLE user_join_group (
  289.                 user_id INT NOT NULL,
  290.                 group_id INT NOT NULL,
  291.                 INDEX IDX_43E5F184A76ED395 (user_id),
  292.                 INDEX IDX_43E5F184FE54D947 (group_id),
  293.                 PRIMARY KEY(user_id, group_id)
  294.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  295.         ');
  296.         $this->addSql('
  297.             CREATE TABLE user_join_team (
  298.                 user_id INT NOT NULL,
  299.                 team_id INT NOT NULL,
  300.                 INDEX IDX_55586662A76ED395 (user_id),
  301.                 INDEX IDX_55586662296CD8AE (team_id),
  302.                 PRIMARY KEY(user_id, team_id)
  303.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  304.         ');
  305.         $this->addSql('
  306.             CREATE TABLE user_join_access_user (
  307.                 user_id INT NOT NULL,
  308.                 access_user_id INT NOT NULL,
  309.                 INDEX IDX_C256DA04A76ED395 (user_id),
  310.                 INDEX IDX_C256DA046F4B0980 (access_user_id),
  311.                 PRIMARY KEY(user_id, access_user_id)
  312.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  313.         ');
  314.         $this->addSql('
  315.             CREATE TABLE user_join_access_group (
  316.                 user_id INT NOT NULL,
  317.                 access_group_id INT NOT NULL,
  318.                 INDEX IDX_65E2BCE4A76ED395 (user_id),
  319.                 INDEX IDX_65E2BCE493411876 (access_group_id),
  320.                 PRIMARY KEY(user_id, access_group_id)
  321.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  322.         ');
  323.         $this->addSql('
  324.             CREATE TABLE user_join_access_chat_user (
  325.                 user_id INT NOT NULL,
  326.                 access_user_id INT NOT NULL,
  327.                 INDEX IDX_213F6F29A76ED395 (user_id),
  328.                 INDEX IDX_213F6F296F4B0980 (access_user_id),
  329.                 PRIMARY KEY(user_id, access_user_id)
  330.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  331.         ');
  332.         $this->addSql('
  333.             CREATE TABLE user_join_access_chat_group (
  334.                 user_id INT NOT NULL,
  335.                 access_group_id INT NOT NULL,
  336.                 INDEX IDX_20DE8924A76ED395 (user_id),
  337.                 INDEX IDX_20DE892493411876 (access_group_id),
  338.                 PRIMARY KEY(user_id, access_group_id)
  339.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
  340.         ');
  341.         $this->addSql('
  342.             ALTER TABLE administrators
  343.                 ADD access_all_users TINYINT(1) NOT NULL,
  344.                 ADD access_all_groups TINYINT(1) NOT NULL,
  345.                 ADD access_chat_all_users TINYINT(1) NOT NULL,
  346.                 ADD access_chat_all_groups TINYINT(1) NOT NULL,
  347.                 ADD access_customer_entity TINYINT(1) NOT NULL,
  348.                 ADD access_customer_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  349.                 ADD access_lead_entity TINYINT(1) NOT NULL,
  350.                 ADD access_lead_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  351.                 ADD access_event_entity TINYINT(1) NOT NULL,
  352.                 ADD access_event_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  353.                 ADD access_feed_entity TINYINT(1) NOT NULL,
  354.                 ADD access_feed_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  355.                 ADD access_issue_entity TINYINT(1) NOT NULL,
  356.                 ADD access_issue_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  357.                 ADD access_message_entity TINYINT(1) NOT NULL,
  358.                 ADD access_message_entity_role LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  359.                 ADD access_all_reports TINYINT(1) NOT NULL,
  360.                 ADD access_all_widgets TINYINT(1) NOT NULL,
  361.                 ADD access_group_permissions TINYINT(1) NOT NULL,
  362.                 CHANGE user_password user_password VARCHAR(255) DEFAULT NULL
  363.         ');
  364.         $stmt $this->connection->prepare('SELECT * FROM administrators');
  365.         $stmt->execute();
  366.         /** @var UserPasswordEncoderInterface $encoder */
  367.         $encoder $this->container->get('security.password_encoder');
  368.         while ($row $stmt->fetch(\PDO::FETCH_OBJ)) {
  369.             $levels $row->levels explode(','$row->levels) : [];
  370.             $colors $row->colors explode(','$row->colors) : [];
  371.             $phones $row->phones unserialize($row->phones) : [];
  372.             $networks $row->networks unserialize($row->networks) : [];
  373.             $tmp = [];
  374.             foreach ($levels as $level) {
  375.                 switch ((int) $level) {
  376.                     case 1$tmp[] = 'red'; break;
  377.                     case 2$tmp[] = 'copper'; break;
  378.                     case 3$tmp[] = 'bronze'; break;
  379.                     case 4$tmp[] = 'silver'; break;
  380.                     case 5$tmp[] = 'gold'; break;
  381.                     case 6$tmp[] = 'platinum'; break;
  382.                     case 7$tmp[] = 'diamond'; break;
  383.                 }
  384.             }
  385.             $levels = !empty($tmp) ? $tmp null;
  386.             $tmp = [];
  387.             foreach ($colors as $color) {
  388.                 if (\in_array($color, [
  389.                     '006400'// green
  390.                     'eeee00'// yellow
  391.                     'ffa500'// orange
  392.                     'ff0000'// red
  393.                     'ffc0cb'// pink
  394.                     '0000ff'// blue
  395.                     'a020f0'// purple
  396.                     '00ffff'// aqua
  397.                     '00ff00'// lime
  398.                     '999999'// grey
  399.                 ])) {
  400.                     $tmp[] = $color;
  401.                 }
  402.             }
  403.             $colors = !empty($tmp) ? $tmp null;
  404.             $tmp = [];
  405.             foreach ($phones as $key => $value) {
  406.                 $tmp[] = [
  407.                     'key' => $key,
  408.                     'value' => $value,
  409.                 ];
  410.             }
  411.             $phones = !empty($tmp) ? $tmp null;
  412.             $tmp = [];
  413.             foreach ($networks as $key => $value) {
  414.                 $tmp[] = [
  415.                     'key' => $key,
  416.                     'value' => $value,
  417.                 ];
  418.             }
  419.             $networks = !empty($tmp) ? $tmp null;
  420.             $users $row->owner_administrators explode(','$row->owner_administrators) : [];
  421.             $groups $row->owner_administrators_groups explode(','$row->owner_administrators_groups) : [];
  422.             $chatUsers $row->chats_administrators explode(','$row->chats_administrators) : [];
  423.             $chatGroups $row->chats_administrators_groups explode(','$row->chats_administrators_groups) : [];
  424.             $reports $row->reports explode(','$row->reports) : [];
  425.             $widgets $row->dashboard explode(','$row->dashboard) : [];
  426.             $permissions $row->permissions json_decode($row->permissionstrue) : [];
  427.             $accessCustomerEntityRoles = [];
  428.             $accessLeadEntityRoles = [];
  429.             $accessEventEntityRoles = [];
  430.             if (\array_key_exists('customers'$permissions)) {
  431.                 if (\in_array('new'$permissions['customers'])) {
  432.                     $accessCustomerEntityRoles[] = AccessRoleType::CREATE;
  433.                 }
  434.                 if (\in_array('edit'$permissions['customers'])) {
  435.                     $accessCustomerEntityRoles[] = AccessRoleType::EDIT;
  436.                 }
  437.                 if (\in_array('delete'$permissions['customers'])) {
  438.                     $accessCustomerEntityRoles[] = AccessRoleType::DELETE;
  439.                 }
  440.             }
  441.             if (\array_key_exists('leads'$permissions)) {
  442.                 if (\in_array('new'$permissions['leads'])) {
  443.                     $accessLeadEntityRoles[] = AccessRoleType::CREATE;
  444.                 }
  445.                 if (\in_array('edit'$permissions['leads'])) {
  446.                     $accessLeadEntityRoles[] = AccessRoleType::EDIT;
  447.                 }
  448.                 if (\in_array('delete'$permissions['leads'])) {
  449.                     $accessLeadEntityRoles[] = AccessRoleType::DELETE;
  450.                 }
  451.             }
  452.             if (\array_key_exists('events'$permissions)) {
  453.                 if (\in_array('new'$permissions['events'])) {
  454.                     $accessEventEntityRoles[] = AccessRoleType::CREATE;
  455.                 }
  456.                 if (\in_array('edit'$permissions['events'])) {
  457.                     $accessEventEntityRoles[] = AccessRoleType::EDIT;
  458.                 }
  459.                 if (\in_array('delete'$permissions['events'])) {
  460.                     $accessEventEntityRoles[] = AccessRoleType::DELETE;
  461.                 }
  462.             }
  463.             if (\array_key_exists('*'$permissions)) {
  464.                 $accessCustomerEntityRoles = [
  465.                     AccessRoleType::CREATE,
  466.                     AccessRoleType::EDIT,
  467.                     AccessRoleType::DELETE,
  468.                 ];
  469.                 $accessLeadEntityRoles = [
  470.                     AccessRoleType::CREATE,
  471.                     AccessRoleType::EDIT,
  472.                     AccessRoleType::DELETE,
  473.                 ];
  474.                 $accessEventEntityRoles = [
  475.                     AccessRoleType::CREATE,
  476.                     AccessRoleType::EDIT,
  477.                     AccessRoleType::DELETE,
  478.                 ];
  479.             }
  480.             if (empty($accessCustomerEntityRoles)) {
  481.                 $accessCustomerEntityRoles null;
  482.             }
  483.             if (empty($accessLeadEntityRoles)) {
  484.                 $accessLeadEntityRoles null;
  485.             }
  486.             if (empty($accessEventEntityRoles)) {
  487.                 $accessEventEntityRoles null;
  488.             }
  489.             // set random password when missing
  490.             $row->raw_password $row->raw_password ?: StringUtil::generatePassword();
  491.             $this->addSql('UPDATE administrators SET user_password = :user_password, raw_password = :raw_password, levels = :levels, colors = :colors, phones = :phones, networks = :networks, access_all_users = :access_all_users, access_all_groups = :access_all_groups, access_chat_all_users = :access_chat_all_users, access_chat_all_groups = :access_chat_all_groups, access_all_reports = :access_all_reports, access_all_widgets = :access_all_widgets, access_customer_entity = :access_customer_entity, access_customer_entity_role = :access_customer_entity_role, access_lead_entity = :access_lead_entity, access_lead_entity_role = :access_lead_entity_role, access_event_entity = :access_event_entity, access_event_entity_role = :access_event_entity_role, access_feed_entity = :access_feed_entity, access_feed_entity_role = :access_feed_entity_role, access_issue_entity = :access_issue_entity, access_issue_entity_role = :access_issue_entity_role, access_message_entity = :access_message_entity, access_message_entity_role = :access_message_entity_role, access_group_permissions = :access_group_permissions WHERE id = :id', [
  492.                 'id' => $row->id,
  493.                 'user_password' => $encoder->encodePassword(new User(), $row->raw_password),
  494.                 'raw_password' => $row->raw_password,
  495.                 'levels' => $levels serialize($levels) : null,
  496.                 'colors' => $colors serialize($colors) : null,
  497.                 'phones' => $phones serialize($phones) : null,
  498.                 'networks' => $networks serialize($networks) : null,
  499.                 'access_all_users' => (int) \in_array('*'$users),
  500.                 'access_all_groups' => (int) \in_array('*'$groups),
  501.                 'access_chat_all_users' => (int) \in_array('*'$chatUsers),
  502.                 'access_chat_all_groups' => (int) \in_array('*'$chatGroups),
  503.                 'access_all_reports' => (int) \in_array('*'$reports),
  504.                 'access_all_widgets' => (int) \in_array('*'$widgets),
  505.                 'access_customer_entity' => (int) (\array_key_exists('*'$permissions) || \array_key_exists('customers'$permissions)),
  506.                 'access_customer_entity_role' => $accessCustomerEntityRoles serialize($accessCustomerEntityRoles) : null,
  507.                 'access_lead_entity' => (int) (\array_key_exists('*'$permissions) || \array_key_exists('leads'$permissions)),
  508.                 'access_lead_entity_role' => $accessLeadEntityRoles serialize($accessLeadEntityRoles) : null,
  509.                 'access_event_entity' => (int) (\array_key_exists('*'$permissions) || \array_key_exists('events'$permissions)),
  510.                 'access_event_entity_role' => $accessEventEntityRoles serialize($accessEventEntityRoles) : null,
  511.                 'access_feed_entity' => (int) (== $row->view_profile_feeds),
  512.                 'access_feed_entity_role' => == $row->view_profile_feeds
  513.                     serialize([
  514.                         AccessRoleType::CREATE,
  515.                         AccessRoleType::EDIT,
  516.                         AccessRoleType::DELETE,
  517.                     ])
  518.                     : null,
  519.                 'access_issue_entity' => (int) (== $row->view_profile_issues),
  520.                 'access_issue_entity_role' => == $row->view_profile_issues
  521.                     serialize([
  522.                         AccessRoleType::CREATE,
  523.                         AccessRoleType::EDIT,
  524.                         AccessRoleType::DELETE,
  525.                     ])
  526.                     : null,
  527.                 'access_message_entity' => (int) (== $row->view_profile_messages),
  528.                 'access_message_entity_role' => == $row->view_profile_messages
  529.                     serialize([
  530.                         AccessRoleType::CREATE,
  531.                         AccessRoleType::EDIT,
  532.                         AccessRoleType::DELETE,
  533.                     ])
  534.                     : null,
  535.                 'access_group_permissions' => (int) (== $row->group_permissions),
  536.             ]);
  537.             if ($row->administrators_groups) {
  538.                 $adminGroups explode(','$row->administrators_groups);
  539.                 $adminGroups array_unique($adminGroups);
  540.                 foreach ($adminGroups as $group) {
  541.                     if ($group && '*' !== $group) {
  542.                         $this->addSql('INSERT INTO user_join_group (user_id, group_id) values (:user_id, :group_id)', [
  543.                             'user_id' => $row->id,
  544.                             'group_id' => $group,
  545.                         ]);
  546.                     }
  547.                 }
  548.             }
  549.             if ($row->administrators_teams) {
  550.                 $adminTeams explode(','$row->administrators_teams);
  551.                 $adminTeams array_unique($adminTeams);
  552.                 foreach ($adminTeams as $team) {
  553.                     if ($team && '*' !== $team) {
  554.                         $this->addSql('INSERT INTO user_join_team (user_id, team_id) values (:user_id, :team_id)', [
  555.                             'user_id' => $row->id,
  556.                             'team_id' => $team,
  557.                         ]);
  558.                     }
  559.                 }
  560.             }
  561.             if (!empty($users)) {
  562.                 $users array_unique($users);
  563.                 foreach ($users as $user) {
  564.                     if ($user && '*' !== $user) {
  565.                         $this->addSql('INSERT INTO user_join_access_user (user_id, access_user_id) values (:user_id, :access_user_id)', [
  566.                             'user_id' => $row->id,
  567.                             'access_user_id' => $user,
  568.                         ]);
  569.                     }
  570.                 }
  571.             }
  572.             if (!empty($groups)) {
  573.                 $groups array_unique($groups);
  574.                 foreach ($groups as $group) {
  575.                     if ($group && '*' !== $group) {
  576.                         $this->addSql('INSERT INTO user_join_access_group (user_id, access_group_id) values (:user_id, :access_group_id)', [
  577.                             'user_id' => $row->id,
  578.                             'access_group_id' => $group,
  579.                         ]);
  580.                     }
  581.                 }
  582.             }
  583.             if (!empty($chatUsers)) {
  584.                 $users array_unique($chatUsers);
  585.                 foreach ($users as $user) {
  586.                     if ($user && '*' !== $user) {
  587.                         $this->addSql('INSERT INTO user_join_access_chat_user (user_id, access_user_id) values (:user_id, :access_user_id)', [
  588.                             'user_id' => $row->id,
  589.                             'access_user_id' => $user,
  590.                         ]);
  591.                     }
  592.                 }
  593.             }
  594.             if (!empty($chatGroups)) {
  595.                 $groups array_unique($chatGroups);
  596.                 foreach ($groups as $group) {
  597.                     if ($group && '*' !== $group) {
  598.                         $this->addSql('INSERT INTO user_join_access_chat_group (user_id, access_group_id) values (:user_id, :access_group_id)', [
  599.                             'user_id' => $row->id,
  600.                             'access_group_id' => $group,
  601.                         ]);
  602.                     }
  603.                 }
  604.             }
  605.             if (!empty($reports)) {
  606.                 $reports array_unique($reports);
  607.                 foreach ($reports as $report) {
  608.                     if ($report && '*' !== $report && \array_key_exists($report$this->getReports())) {
  609.                         $report = (int) (array_search($reportarray_keys($this->getReports()))) + 1;
  610.                         $this->addSql('INSERT INTO user_report (object_id, report_id) values (:object_id, :report_id)', [
  611.                             'object_id' => $row->id,
  612.                             'report_id' => $report,
  613.                         ]);
  614.                     }
  615.                 }
  616.             }
  617.             if (!empty($widgets)) {
  618.                 $widgets array_unique($widgets);
  619.                 foreach ($widgets as $widget) {
  620.                     if ($widget && '*' !== $widget) {
  621.                         $tmp = [];
  622.                         if (\array_key_exists($widget$this->getWidgets())) {
  623.                             $tmp[] = $widget;
  624.                         } else {
  625.                             foreach ($this->getWidgets() as $key => $value) {
  626.                                 $legacy $value['legacy'] ?? [];
  627.                                 if (!\is_array($legacy)) {
  628.                                     $legacy = [$legacy];
  629.                                 }
  630.                                 if (\in_array($widget$legacy)) {
  631.                                     $tmp[] = $key;
  632.                                 }
  633.                             }
  634.                         }
  635.                         foreach ($tmp as $widget) {
  636.                             $widget = (int) (array_search($widgetarray_keys($this->getWidgets()))) + 1;
  637.                             $this->addSql('INSERT IGNORE INTO user_widget (object_id, widget_id) values (:object_id, :widget_id)', [
  638.                                 'object_id' => $row->id,
  639.                                 'widget_id' => $widget,
  640.                             ]);
  641.                         }
  642.                     }
  643.                 }
  644.             }
  645.         }
  646.         $this->addSql('RENAME TABLE administrators TO user');
  647.         $this->addSql('ALTER TABLE user ENGINE = InnoDB');
  648.         $this->addSql('ALTER TABLE user CHARACTER SET = utf8mb4');
  649.         $this->addSql('UPDATE user SET status = 0 WHERE status IS NULL');
  650.         $this->addSql('UPDATE user SET view_export_button = 0 WHERE view_export_button IS NULL');
  651.         $this->addSql('UPDATE user SET view_service_notes = 0 WHERE view_service_notes IS NULL');
  652.         $this->addSql('UPDATE user SET view_sales_notes = 0 WHERE view_sales_notes IS NULL');
  653.         $this->addSql('UPDATE user SET view_stage_reset = 0 WHERE view_stage_reset IS NULL');
  654.         $this->addSql('UPDATE user SET view_issue_send_to_field = 0 WHERE view_issue_send_to_field IS NULL');
  655.         $this->addSql('UPDATE user SET view_feed_permission_fields = 0 WHERE view_feed_permission_fields IS NULL');
  656.         $this->addSql('UPDATE user SET view_events = 0 WHERE view_events IS NULL');
  657.         $this->addSql('UPDATE user SET view_all_customers = 0 WHERE view_all_customers IS NULL');
  658.         $this->addSql('UPDATE user SET view_private_files = 0 WHERE view_private_files IS NULL');
  659.         $this->addSql('UPDATE user SET view_source = 0 WHERE view_source IS NULL');
  660.         $this->addSql('UPDATE user SET view_widgets_as_admin = 0 WHERE view_widgets_as_admin IS NULL');
  661.         $this->addSql('UPDATE user SET payments = 0 WHERE payments IS NULL');
  662.         $this->addSql('
  663.             ALTER TABLE user
  664.                 DROP administrators_groups,
  665.                 DROP administrators_teams,
  666.                 DROP group_permissions,
  667.                 DROP permissions,
  668.                 DROP reports,
  669.                 DROP dashboard,
  670.                 DROP owner_administrators,
  671.                 DROP owner_administrators_groups,
  672.                 DROP chats_administrators,
  673.                 DROP chats_administrators_groups,
  674.                 DROP view_event_notifications,
  675.                 DROP view_lead_notifications,
  676.                 DROP view_fee,
  677.                 DROP view_pdf_form,
  678.                 DROP view_document_type,
  679.                 DROP view_message_type,
  680.                 DROP view_profile_messages,
  681.                 DROP view_profile_feeds,
  682.                 DROP view_profile_issues,
  683.                 ADD name VARCHAR(255) DEFAULT NULL,
  684.                 ADD username_canonical VARCHAR(255) NOT NULL,
  685.                 ADD email_canonical VARCHAR(255) NOT NULL,
  686.                 ADD salt VARCHAR(255) DEFAULT NULL,
  687.                 ADD password_requested_at DATETIME DEFAULT NULL,
  688.                 ADD confirmation_token VARCHAR(255) DEFAULT NULL,
  689.                 ADD roles LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\',
  690.                 ADD middle_name VARCHAR(255) DEFAULT NULL,
  691.                 ADD city VARCHAR(255) DEFAULT NULL,
  692.                 ADD state VARCHAR(255) DEFAULT NULL,
  693.                 ADD zip VARCHAR(255) DEFAULT NULL,
  694.                 ADD first_phone VARCHAR(255) DEFAULT NULL,
  695.                 ADD first_fax VARCHAR(255) DEFAULT NULL,
  696.                 ADD first_social_media_account VARCHAR(255) DEFAULT NULL,
  697.                 CHANGE firstname first_name VARCHAR(255) DEFAULT NULL,
  698.                 CHANGE lastname last_name VARCHAR(255) DEFAULT NULL,
  699.                 CHANGE photo photo VARCHAR(255) DEFAULT NULL,
  700.                 CHANGE signature signature LONGTEXT DEFAULT NULL,
  701.                 CHANGE levels levels LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  702.                 CHANGE colors colors LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  703.                 CHANGE rating rating INT DEFAULT NULL,
  704.                 CHANGE ga_secret google_authenticator_secret VARCHAR(255) DEFAULT NULL,
  705.                 CHANGE address street VARCHAR(255) DEFAULT NULL,
  706.                 CHANGE phones phones LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  707.                 CHANGE networks social_media_accounts LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  708.                 CHANGE user_name username VARCHAR(255) NOT NULL,
  709.                 CHANGE email_address email VARCHAR(255) NOT NULL,
  710.                 CHANGE status enabled TINYINT(1) NOT NULL,
  711.                 CHANGE user_password password VARCHAR(255) NOT NULL,
  712.                 CHANGE raw_password plain_password VARCHAR(255) DEFAULT NULL,
  713.                 CHANGE view_export_button allow_data_export TINYINT(1) NOT NULL,
  714.                 CHANGE view_service_notes allow_service_items TINYINT(1) NOT NULL,
  715.                 CHANGE view_sales_notes allow_sales_items TINYINT(1) NOT NULL,
  716.                 CHANGE view_stage_reset allow_stage_reset TINYINT(1) NOT NULL,
  717.                 CHANGE view_issue_send_to_field allow_select_issue_target_user TINYINT(1) NOT NULL,
  718.                 CHANGE view_feed_permission_fields allow_select_feed_target_users TINYINT(1) NOT NULL,
  719.                 CHANGE view_events allow_view_all_events TINYINT(1) NOT NULL,
  720.                 CHANGE view_all_customers allow_view_all_customers TINYINT(1) NOT NULL,
  721.                 CHANGE view_private_files allow_view_private_files TINYINT(1) NOT NULL,
  722.                 CHANGE view_source allow_view_source_value TINYINT(1) NOT NULL,
  723.                 CHANGE view_widgets_as_admin allow_view_widgets_as_admin TINYINT(1) NOT NULL,
  724.                 CHANGE payments allow_invoice_actions TINYINT(1) NOT NULL,
  725.                 CHANGE date_added created_at DATETIME NOT NULL,
  726.                 CHANGE last_modified modified_at DATETIME NOT NULL
  727.         ');
  728.         $this->addSql('UPDATE user SET allow_service_items = 0 WHERE allow_service_items != 1');
  729.         $this->addSql('UPDATE user SET allow_sales_items = 0 WHERE allow_sales_items != 1');
  730.         $this->addSql('UPDATE user SET roles = \'a:0:{}\'');
  731.         $this->addSql('UPDATE user SET roles = \'a:1:{i:0;s:10:"ROLE_ADMIN";}\' WHERE id = 9999');
  732.         $this->addSql('UPDATE user SET street = NULL WHERE street = \'\'');
  733.         $this->addSql('UPDATE user SET name = TRIM(CONCAT_WS(\' \', first_name, last_name))');
  734.         $this->addSql('UPDATE user SET username_canonical = username, email_canonical = email');
  735.         $this->addSql('DELETE FROM user WHERE username_canonical = \'\' OR username_canonical IS NULL OR email_canonical = \'\' OR email_canonical IS NULL');
  736.         $this->addSql('DELETE u1 FROM user u1 INNER JOIN user u2 WHERE u1.id > u2.id AND u1.username_canonical = u2.username_canonical');
  737.         $this->addSql('DELETE u1 FROM user u1 INNER JOIN user u2 WHERE u1.id > u2.id AND u1.email_canonical = u2.email_canonical');
  738.         $this->addSql('CREATE INDEX idx_name ON user (name)');
  739.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D64992FC23A8 ON user (username_canonical)');
  740.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649A0D96FBF ON user (email_canonical)');
  741.         $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649C05FB297 ON user (confirmation_token)');
  742.         $this->addSql('ALTER TABLE user CHARACTER SET = utf8mb4');
  743.         $this->addSql('DELETE FROM user_join_group WHERE user_id NOT IN (SELECT id FROM user)');
  744.         $this->addSql('DELETE FROM user_join_group WHERE group_id NOT IN (SELECT id FROM user_group)');
  745.         $this->addSql('DELETE FROM user_join_team WHERE user_id NOT IN (SELECT id FROM user)');
  746.         $this->addSql('DELETE FROM user_join_team WHERE team_id NOT IN (SELECT id FROM user_team)');
  747.         $this->addSql('DELETE FROM user_join_access_user WHERE user_id NOT IN (SELECT id FROM user)');
  748.         $this->addSql('DELETE FROM user_join_access_user WHERE access_user_id NOT IN (SELECT id FROM user)');
  749.         $this->addSql('DELETE FROM user_join_access_group WHERE user_id NOT IN (SELECT id FROM user)');
  750.         $this->addSql('DELETE FROM user_join_access_group WHERE access_group_id NOT IN (SELECT id FROM user_group)');
  751.         $this->addSql('DELETE FROM user_join_access_chat_user WHERE user_id NOT IN (SELECT id FROM user)');
  752.         $this->addSql('DELETE FROM user_join_access_chat_user WHERE access_user_id NOT IN (SELECT id FROM user)');
  753.         $this->addSql('DELETE FROM user_join_access_chat_group WHERE user_id NOT IN (SELECT id FROM user)');
  754.         $this->addSql('DELETE FROM user_join_access_chat_group WHERE access_group_id NOT IN (SELECT id FROM user_group)');
  755.         $this->addSql('DELETE FROM user_report WHERE object_id NOT IN (SELECT id FROM user)');
  756.         $this->addSql('DELETE FROM user_report WHERE report_id NOT IN (SELECT id FROM report)');
  757.         $this->addSql('DELETE FROM group_report WHERE object_id NOT IN (SELECT id FROM user_group)');
  758.         $this->addSql('DELETE FROM group_report WHERE report_id NOT IN (SELECT id FROM report)');
  759.         $this->addSql('DELETE FROM user_widget WHERE object_id NOT IN (SELECT id FROM user)');
  760.         $this->addSql('DELETE FROM user_widget WHERE widget_id NOT IN (SELECT id FROM widget)');
  761.         $this->addSql('DELETE FROM group_widget WHERE object_id NOT IN (SELECT id FROM user_group)');
  762.         $this->addSql('DELETE FROM group_widget WHERE widget_id NOT IN (SELECT id FROM widget)');
  763.         $this->addSql('ALTER TABLE user_join_group ADD CONSTRAINT FK_43E5F184A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
  764.         $this->addSql('ALTER TABLE user_join_group ADD CONSTRAINT FK_43E5F184FE54D947 FOREIGN KEY (group_id) REFERENCES user_group (id) ON DELETE CASCADE');
  765.         $this->addSql('ALTER TABLE user_join_team ADD CONSTRAINT FK_55586662A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
  766.         $this->addSql('ALTER TABLE user_join_team ADD CONSTRAINT FK_55586662296CD8AE FOREIGN KEY (team_id) REFERENCES user_team (id) ON DELETE CASCADE');
  767.         $this->addSql('ALTER TABLE user_join_access_user ADD CONSTRAINT FK_C256DA04A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
  768.         $this->addSql('ALTER TABLE user_join_access_user ADD CONSTRAINT FK_C256DA046F4B0980 FOREIGN KEY (access_user_id) REFERENCES user (id) ON DELETE CASCADE');
  769.         $this->addSql('ALTER TABLE user_join_access_group ADD CONSTRAINT FK_65E2BCE4A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
  770.         $this->addSql('ALTER TABLE user_join_access_group ADD CONSTRAINT FK_65E2BCE493411876 FOREIGN KEY (access_group_id) REFERENCES user_group (id) ON DELETE CASCADE');
  771.         $this->addSql('ALTER TABLE user_join_access_chat_user ADD CONSTRAINT FK_213F6F29A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
  772.         $this->addSql('ALTER TABLE user_join_access_chat_user ADD CONSTRAINT FK_213F6F296F4B0980 FOREIGN KEY (access_user_id) REFERENCES user (id) ON DELETE CASCADE');
  773.         $this->addSql('ALTER TABLE user_join_access_chat_group ADD CONSTRAINT FK_20DE8924A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
  774.         $this->addSql('ALTER TABLE user_join_access_chat_group ADD CONSTRAINT FK_20DE892493411876 FOREIGN KEY (access_group_id) REFERENCES user_group (id) ON DELETE CASCADE');
  775.         $this->addSql('ALTER TABLE user_report ADD CONSTRAINT FK_A17D6CB9232D562B FOREIGN KEY (object_id) REFERENCES user (id) ON DELETE CASCADE');
  776.         $this->addSql('ALTER TABLE user_report ADD CONSTRAINT FK_A17D6CB94BD2A4C0 FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE');
  777.         $this->addSql('ALTER TABLE group_report ADD CONSTRAINT FK_17A9AF54232D562B FOREIGN KEY (object_id) REFERENCES user_group (id) ON DELETE CASCADE');
  778.         $this->addSql('ALTER TABLE group_report ADD CONSTRAINT FK_17A9AF544BD2A4C0 FOREIGN KEY (report_id) REFERENCES report (id) ON DELETE CASCADE');
  779.         $this->addSql('ALTER TABLE user_widget ADD CONSTRAINT FK_E0AB05ED232D562B FOREIGN KEY (object_id) REFERENCES user (id) ON DELETE CASCADE');
  780.         $this->addSql('ALTER TABLE user_widget ADD CONSTRAINT FK_E0AB05EDFBE885E2 FOREIGN KEY (widget_id) REFERENCES widget (id) ON DELETE CASCADE');
  781.         $this->addSql('ALTER TABLE group_widget ADD CONSTRAINT FK_567FC600232D562B FOREIGN KEY (object_id) REFERENCES user_group (id) ON DELETE CASCADE');
  782.         $this->addSql('ALTER TABLE group_widget ADD CONSTRAINT FK_567FC600FBE885E2 FOREIGN KEY (widget_id) REFERENCES widget (id) ON DELETE CASCADE');
  783.     }
  784.     public function down(Schema $schema): void
  785.     {
  786.         // this down() migration is auto-generated, please modify it to your needs
  787.         $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
  788.         $this->addSql('ALTER TABLE group_widget DROP FOREIGN KEY FK_567FC600FBE885E2');
  789.         $this->addSql('ALTER TABLE group_widget DROP FOREIGN KEY FK_567FC600232D562B');
  790.         $this->addSql('ALTER TABLE user_widget DROP FOREIGN KEY FK_E0AB05EDFBE885E2');
  791.         $this->addSql('ALTER TABLE user_widget DROP FOREIGN KEY FK_E0AB05ED232D562B');
  792.         $this->addSql('ALTER TABLE group_report DROP FOREIGN KEY FK_17A9AF544BD2A4C0');
  793.         $this->addSql('ALTER TABLE group_report DROP FOREIGN KEY FK_17A9AF54232D562B');
  794.         $this->addSql('ALTER TABLE user_report DROP FOREIGN KEY FK_A17D6CB94BD2A4C0');
  795.         $this->addSql('ALTER TABLE user_report DROP FOREIGN KEY FK_A17D6CB9232D562B');
  796.         $this->addSql('ALTER TABLE user_join_access_chat_group DROP FOREIGN KEY FK_20DE892493411876');
  797.         $this->addSql('ALTER TABLE user_join_access_chat_group DROP FOREIGN KEY FK_20DE8924A76ED395');
  798.         $this->addSql('ALTER TABLE user_join_access_chat_user DROP FOREIGN KEY FK_213F6F296F4B0980');
  799.         $this->addSql('ALTER TABLE user_join_access_chat_user DROP FOREIGN KEY FK_213F6F29A76ED395');
  800.         $this->addSql('ALTER TABLE user_join_access_group DROP FOREIGN KEY FK_65E2BCE493411876');
  801.         $this->addSql('ALTER TABLE user_join_access_group DROP FOREIGN KEY FK_65E2BCE4A76ED395');
  802.         $this->addSql('ALTER TABLE user_join_access_user DROP FOREIGN KEY FK_C256DA046F4B0980');
  803.         $this->addSql('ALTER TABLE user_join_access_user DROP FOREIGN KEY FK_C256DA04A76ED395');
  804.         $this->addSql('ALTER TABLE user_join_team DROP FOREIGN KEY FK_55586662296CD8AE');
  805.         $this->addSql('ALTER TABLE user_join_team DROP FOREIGN KEY FK_55586662A76ED395');
  806.         $this->addSql('ALTER TABLE user_join_group DROP FOREIGN KEY FK_43E5F184FE54D947');
  807.         $this->addSql('ALTER TABLE user_join_group DROP FOREIGN KEY FK_43E5F184A76ED395');
  808.         $this->addSql('RENAME TABLE user_team TO administrators_teams');
  809.         $this->addSql('ALTER TABLE administrators_teams ENGINE = MyISAM');
  810.         $this->addSql('ALTER TABLE administrators_teams CHARACTER SET = latin1');
  811.         $this->addSql('
  812.             ALTER TABLE administrators_teams
  813.                 ADD type TINYINT(1) DEFAULT \'0\' AFTER name,
  814.                 CHANGE name name VARCHAR(32) NOT NULL
  815.         ');
  816.         $this->addSql('UPDATE administrators_teams SET type = \'1\'');
  817.         $this->addSql('RENAME TABLE user_group TO administrators_groups');
  818.         $this->addSql('ALTER TABLE administrators_groups ENGINE = MyISAM');
  819.         $this->addSql('ALTER TABLE administrators_groups CHARACTER SET = latin1');
  820.         $this->addSql('
  821.             ALTER TABLE administrators_groups
  822.                 DROP access_customer_entity,
  823.                 DROP access_customer_entity_role,
  824.                 DROP access_lead_entity,
  825.                 DROP access_lead_entity_role,
  826.                 DROP access_event_entity,
  827.                 DROP access_event_entity_role,
  828.                 DROP access_feed_entity,
  829.                 DROP access_feed_entity_role,
  830.                 DROP access_issue_entity,
  831.                 DROP access_issue_entity_role,
  832.                 DROP access_message_entity,
  833.                 DROP access_message_entity_role,
  834.                 DROP access_all_reports,
  835.                 DROP access_all_widgets,
  836.                 ADD permissions TEXT DEFAULT NULL AFTER name,
  837.                 ADD reports TEXT DEFAULT NULL AFTER permissions,
  838.                 ADD dashboard TEXT DEFAULT NULL AFTER reports,
  839.                 CHANGE name name VARCHAR(32) NOT NULL
  840.         ');
  841.         $stmt $this->connection->prepare('SELECT id, levels, colors, phones, social_media_accounts, plain_password FROM user');
  842.         $stmt->execute();
  843.         while ($row $stmt->fetch(\PDO::FETCH_OBJ)) {
  844.             $levels $row->levels unserialize($row->levels) : [];
  845.             $colors $row->colors unserialize($row->colors) : [];
  846.             $phones $row->phones unserialize($row->phones) : [];
  847.             $networks $row->social_media_accounts unserialize($row->social_media_accounts) : [];
  848.             $tmp = [];
  849.             foreach ($levels as $level) {
  850.                 switch ($level) {
  851.                     case 'red'$tmp[] = 1; break;
  852.                     case 'copper'$tmp[] = 2; break;
  853.                     case 'bronze'$tmp[] = 3; break;
  854.                     case 'silver'$tmp[] = 4; break;
  855.                     case 'gold'$tmp[] = 5; break;
  856.                     case 'platinum'$tmp[] = 6; break;
  857.                     case 'diamond'$tmp[] = 7; break;
  858.                 }
  859.             }
  860.             $levels = !empty($tmp) ? $tmp null;
  861.             $tmp = [];
  862.             foreach ($colors as $color) {
  863.                 if (\in_array($color, [
  864.                     '006400'// green
  865.                     'eeee00'// yellow
  866.                     'ffa500'// orange
  867.                     'ff0000'// red
  868.                     'ffc0cb'// pink
  869.                     '0000ff'// blue
  870.                     'a020f0'// purple
  871.                     '00ffff'// aqua
  872.                     '00ff00'// lime
  873.                     '999999'// grey
  874.                 ])) {
  875.                     $tmp[] = $color;
  876.                 }
  877.             }
  878.             $colors = !empty($tmp) ? $tmp null;
  879.             $tmp = [];
  880.             foreach ($phones as $phone) {
  881.                 $tmp[$phone['key']] = $phone['value'];
  882.             }
  883.             $phones = !empty($tmp) ? $tmp null;
  884.             $tmp = [];
  885.             foreach ($networks as $network) {
  886.                 $tmp[$network['key']] = $network['value'];
  887.             }
  888.             $networks = !empty($tmp) ? $tmp null;
  889.             $this->addSql('UPDATE user SET password = :password, levels = :levels, phones = :phones, social_media_accounts = :networks WHERE id = :id', [
  890.                 'id' => $row->id,
  891.                 'password' => $row->plain_password sha1($row->plain_password) : null,
  892.                 'levels' => $levels implode(','$levels) : null,
  893.                 'phones' => $phones serialize($phones) : null,
  894.                 'networks' => $networks serialize($networks) : null,
  895.             ]);
  896.         }
  897.         $this->addSql('RENAME TABLE user TO administrators');
  898.         $this->addSql('ALTER TABLE administrators ENGINE = MyISAM');
  899.         $this->addSql('ALTER TABLE administrators CHARACTER SET = latin1');
  900.         $this->addSql('DROP INDEX idx_name ON administrators');
  901.         $this->addSql('DROP INDEX UNIQ_8D93D64992FC23A8 ON administrators');
  902.         $this->addSql('DROP INDEX UNIQ_8D93D649A0D96FBF ON administrators');
  903.         $this->addSql('DROP INDEX UNIQ_8D93D649C05FB297 ON administrators');
  904.         $this->addSql('
  905.             ALTER TABLE administrators
  906.                 DROP name,
  907.                 DROP username_canonical,
  908.                 DROP email_canonical,
  909.                 DROP salt,
  910.                 DROP password_requested_at,
  911.                 DROP confirmation_token,
  912.                 DROP roles,
  913.                 DROP first_phone,
  914.                 DROP first_fax,
  915.                 DROP first_social_media_account,
  916.                 DROP access_all_users,
  917.                 DROP access_all_groups,
  918.                 DROP access_chat_all_users,
  919.                 DROP access_chat_all_groups,
  920.                 DROP access_customer_entity,
  921.                 DROP access_customer_entity_role,
  922.                 DROP access_lead_entity,
  923.                 DROP access_lead_entity_role,
  924.                 DROP access_event_entity,
  925.                 DROP access_event_entity_role,
  926.                 DROP access_feed_entity,
  927.                 DROP access_feed_entity_role,
  928.                 DROP access_issue_entity,
  929.                 DROP access_issue_entity_role,
  930.                 DROP access_message_entity,
  931.                 DROP access_message_entity_role,
  932.                 DROP access_all_reports,
  933.                 DROP access_all_widgets,
  934.                 ADD administrators_groups TEXT NOT NULL AFTER id,
  935.                 ADD administrators_teams TEXT DEFAULT NULL AFTER administrators_groups,
  936.                 ADD group_permissions TINYINT(1) DEFAULT \'0\' AFTER status,
  937.                 ADD permissions TEXT DEFAULT NULL AFTER group_permissions,
  938.                 ADD reports TEXT DEFAULT NULL AFTER payments,
  939.                 ADD dashboard TEXT DEFAULT NULL AFTER reports,
  940.                 ADD owner_administrators TEXT DEFAULT NULL AFTER colors,
  941.                 ADD owner_administrators_groups TEXT DEFAULT NULL AFTER owner_administrators,
  942.                 ADD chats_administrators TEXT DEFAULT NULL AFTER owner_administrators_groups,
  943.                 ADD chats_administrators_groups TEXT DEFAULT NULL AFTER chats_administrators,
  944.                 ADD view_event_notifications TINYINT(1) DEFAULT \'0\' AFTER view_events,
  945.                 ADD view_lead_notifications TINYINT(1) DEFAULT \'0\' AFTER view_event_notifications,
  946.                 ADD view_fee TINYINT(1) DEFAULT \'0\' AFTER view_lead_notifications,
  947.                 ADD view_pdf_form TINYINT(1) DEFAULT \'0\' AFTER view_widgets_as_admin,
  948.                 ADD view_document_type TINYINT(1) DEFAULT \'0\' AFTER view_pdf_form,
  949.                 ADD view_message_type TINYINT(1) DEFAULT \'0\' AFTER view_document_type,
  950.                 ADD view_profile_messages TINYINT(1) DEFAULT \'0\' AFTER view_export_button,
  951.                 ADD view_profile_feeds TINYINT(1) DEFAULT \'0\' AFTER view_profile_messages,
  952.                 ADD view_profile_issues TINYINT(1) DEFAULT \'0\' AFTER view_profile_feeds,
  953.                 CHANGE first_name firstname VARCHAR(32) DEFAULT NULL,
  954.                 CHANGE last_name lastname VARCHAR(32) DEFAULT NULL,
  955.                 CHANGE photo photo VARCHAR(255) DEFAULT NULL,
  956.                 CHANGE signature signature TEXT DEFAULT NULL,
  957.                 CHANGE levels levels TEXT DEFAULT NULL,
  958.                 CHANGE colors colors TEXT DEFAULT NULL,
  959.                 CHANGE rating rating TINYINT(1) DEFAULT \'0\',
  960.                 CHANGE google_authenticator_secret ga_secret VARCHAR(40) DEFAULT NULL,
  961.                 CHANGE street address TEXT DEFAULT NULL,
  962.                 CHANGE phones phones LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  963.                 CHANGE social_media_accounts networks LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  964.                 CHANGE username user_name VARCHAR(32) NOT NULL DEFAULT \'\',
  965.                 CHANGE email email_address VARCHAR(96) DEFAULT NULL,
  966.                 CHANGE enabled status TINYINT(1) DEFAULT \'0\',
  967.                 CHANGE password user_password VARCHAR(40) NOT NULL,
  968.                 CHANGE plain_password raw_password VARCHAR(40) DEFAULT NULL,
  969.                 CHANGE allow_data_export view_export_button TINYINT(1) DEFAULT \'0\',
  970.                 CHANGE allow_service_items view_service_notes TINYINT(1) DEFAULT \'0\',
  971.                 CHANGE allow_sales_items view_sales_notes TINYINT(1) DEFAULT \'0\',
  972.                 CHANGE allow_stage_reset view_stage_reset TINYINT(1) DEFAULT \'0\',
  973.                 CHANGE allow_select_issue_target_user view_issue_send_to_field TINYINT(1) DEFAULT \'0\',
  974.                 CHANGE allow_select_feed_target_users view_feed_permission_fields TINYINT(1) DEFAULT \'0\',
  975.                 CHANGE allow_view_all_events view_events TINYINT(1) DEFAULT \'0\',
  976.                 CHANGE allow_view_all_customers view_all_customers TINYINT(1) DEFAULT \'0\',
  977.                 CHANGE allow_view_private_files view_private_files TINYINT(1) DEFAULT \'0\',
  978.                 CHANGE allow_view_source_value view_source TINYINT(1) DEFAULT \'0\',
  979.                 CHANGE allow_view_widgets_as_admin view_widgets_as_admin TINYINT(1) DEFAULT \'0\',
  980.                 CHANGE allow_invoice_actions payments TINYINT(1) DEFAULT \'0\',
  981.                 CHANGE created_at date_added DATETIME DEFAULT NULL,
  982.                 CHANGE modified_at last_modified DATETIME DEFAULT NULL
  983.         ');
  984.         $this->addSql('UPDATE administrators SET firstname = TRIM(CONCAT_WS(\' \', firstname, middle_name))');
  985.         $this->addSql('UPDATE administrators SET address = TRIM(CONCAT_WS("\n", address, city, state, zip))');
  986.         $this->addSql('
  987.             ALTER TABLE administrators
  988.                 DROP middle_name,
  989.                 DROP city,
  990.                 DROP state,
  991.                 DROP zip
  992.         ');
  993.         $stmt $this->connection->prepare('SELECT * FROM user_join_group');
  994.         $stmt->execute();
  995.         $users = [];
  996.         while ($row $stmt->fetch(\PDO::FETCH_OBJ)) {
  997.             $users[$row->user_id][] = $row->group_id;
  998.         }
  999.         foreach ($users as $key => $value) {
  1000.             $this->addSql('UPDATE administrators SET administrators_groups = :administrators_groups WHERE id = :id', [
  1001.                 'id' => $key,
  1002.                 'administrators_groups' => implode(','$value),
  1003.             ]);
  1004.         }
  1005.         $this->addSql('DROP TABLE user_join_group');
  1006.         $stmt $this->connection->prepare('SELECT * FROM user_join_team');
  1007.         $stmt->execute();
  1008.         $users = [];
  1009.         while ($row $stmt->fetch(\PDO::FETCH_OBJ)) {
  1010.             $users[$row->user_id][] = $row->team_id;
  1011.         }
  1012.         foreach ($users as $key => $value) {
  1013.             $this->addSql('UPDATE administrators SET administrators_teams = :administrators_teams WHERE id = :id', [
  1014.                 'id' => $key,
  1015.                 'administrators_teams' => implode(','$value),
  1016.             ]);
  1017.         }
  1018.         $this->addSql('DROP TABLE user_join_team');
  1019.         // @todo: import permissions manually
  1020.         $this->addSql('DROP TABLE user_report');
  1021.         $this->addSql('DROP TABLE group_report');
  1022.         $this->addSql('DROP TABLE report');
  1023.         $this->addSql('DROP TABLE user_widget');
  1024.         $this->addSql('DROP TABLE group_widget');
  1025.         $this->addSql('DROP TABLE widget');
  1026.         $this->addSql('DROP TABLE user_join_access_user');
  1027.         $this->addSql('DROP TABLE user_join_access_group');
  1028.         $this->addSql('DROP TABLE user_join_access_chat_user');
  1029.         $this->addSql('DROP TABLE user_join_access_chat_group');
  1030.         // @todo: backup table data
  1031.         $this->addSql('
  1032.             CREATE TABLE administrators_favorites (
  1033.                 id INT AUTO_INCREMENT NOT NULL,
  1034.                 administrators_id INT NOT NULL,
  1035.                 title VARCHAR(255) NOT NULL COLLATE latin1_swedish_ci,
  1036.                 url VARCHAR(255) NOT NULL COLLATE latin1_swedish_ci,
  1037.                 params LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
  1038.                 INDEX idx_administrators_id (administrators_id),
  1039.                 PRIMARY KEY(id)
  1040.             ) DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ENGINE = MyISAM
  1041.         ');
  1042.     }
  1043.     /**
  1044.      * @return array
  1045.      */
  1046.     private function getReports(): array
  1047.     {
  1048.         return [
  1049.             // Collection
  1050.             'report_collection' => ['name' => 'Collection''category' => 'Collection'],
  1051.             'report_collection_reps' => ['name' => 'Collection Reps''category' => 'Collection'],
  1052.             'report_collection_colors' => ['name' => 'Collection Colors''category' => 'Collection'],
  1053.             'report_collectors' => ['name' => 'Collectors''category' => 'Collection'],
  1054.             // Service
  1055.             'report_resolution' => ['name' => 'Resolution''category' => 'Service'],
  1056.             'report_complaints' => ['name' => 'Complaints''category' => 'Service'],
  1057.             'report_tax_returns' => ['name' => 'Tax Returns''category' => 'Service'],
  1058.             'report_upsell_request' => ['name' => 'Upsell Request''category' => 'Service'],
  1059.             'report_worktime' => ['name' => 'Work Time''category' => 'Service'],
  1060.             'report_contacts' => ['name' => 'Contacts''category' => 'Service'],
  1061.             'report_last_contact' => ['name' => 'Last Contact''category' => 'Service'],
  1062.             'report_employee_tracker' => ['name' => 'Employee Tracker''category' => 'Service'],
  1063.             'report_time_summary' => ['name' => 'Time Summary''category' => 'Service'],
  1064.             'report_closed' => ['name' => 'Closed Cases''category' => 'Service'],
  1065.             'report_last_qa' => ['name' => 'Last QA''category' => 'Service'],
  1066.             'report_notes' => ['name' => 'Notes''category' => 'Service'],
  1067.             'report_stages' => ['name' => 'Stages''category' => 'Service'],
  1068.             'report_stage_items' => ['name' => 'Stage Items''category' => 'Service'],
  1069.             'report_completed_stage_items' => ['name' => 'Completed Stage Items''category' => 'Service'],
  1070.             'report_service_reps' => ['name' => 'Service Reps''category' => 'Service'],
  1071.             'report_star_rating' => ['name' => 'Star Rating''category' => 'Service'],
  1072.             'report_faxes' => ['name' => 'Faxes''category' => 'Service'],
  1073.             // Sales
  1074.             'report_sales_overview' => ['name' => 'Overview''category' => 'Sales'],
  1075.             'report_sales_payments' => ['name' => 'Payments''category' => 'Sales'],
  1076.             'report_sales_scheduled' => ['name' => 'Scheduled''category' => 'Sales'],
  1077.             'report_sales_balances' => ['name' => 'Open Balances''category' => 'Sales'],
  1078.             'report_sales_payroll' => ['name' => 'Payroll''category' => 'Sales'],
  1079.             'report_sales' => ['name' => 'Cash & Fees''category' => 'Sales'],
  1080.             'report_sales_mini' => ['name' => 'Leaderboard''category' => 'Sales'],
  1081.             'report_upsell' => ['name' => 'Upsell Search''category' => 'Sales'],
  1082.             'report_interviews' => ['name' => 'Interviews''category' => 'Sales'],
  1083.             'report_sales_fees' => ['name' => 'Fees''category' => 'Sales'],
  1084.             // Marketing
  1085.             'report_source_tiers' => ['name' => 'Source Tiers''category' => 'Marketing'],
  1086.             'report_summary' => ['name' => 'Summary''category' => 'Marketing'],
  1087.             'report_revenue_sources' => ['name' => 'Revenue Sources''category' => 'Marketing'],
  1088.             'report_google_keywords' => ['name' => 'Google Keywords''category' => 'Marketing'],
  1089.             'report_bing_keywords' => ['name' => 'Bing Keywords''category' => 'Marketing'],
  1090.             'report_lead_dispositions' => ['name' => 'Lead Dispositions''category' => 'Marketing'],
  1091.             'report_lead_tax_debt' => ['name' => 'Lead Tax Debt''category' => 'Marketing'],
  1092.             'report_sources_campaign' => ['name' => 'Sources: Campaign''category' => 'Marketing'],
  1093.             'report_sources_parent' => ['name' => 'Sources: Parent''category' => 'Marketing'],
  1094.             'report_documents_log' => ['name' => 'Group Emails/Docs''category' => 'Marketing'],
  1095.             // Administrator
  1096.             'report_outbounds' => ['name' => 'Outbounds''category' => 'Administrator'],
  1097.             'report_revenue_reps' => ['name' => 'Revenue Reps''category' => 'Administrator'],
  1098.             'report_revenue_tiers' => ['name' => 'Revenue Tiers''category' => 'Administrator'],
  1099.             'report_last_login' => ['name' => 'Last Login''category' => 'Administrator'],
  1100.             'report_chat_messages' => ['name' => 'Chat Messages''category' => 'Administrator'],
  1101.             'report_sales_goals' => ['name' => 'Goals''category' => 'Administrator'],
  1102.             // Dialers
  1103.             'report_transfer' => ['name' => 'Transfer''category' => 'Dialers'],
  1104.             'report_transfer_reps' => ['name' => 'Transfer Reps''category' => 'Dialers'],
  1105.             'report_transfer_dialers' => ['name' => 'Transfer Dialers''category' => 'Dialers'],
  1106.             'report_transfer_tiers' => ['name' => 'Transfer Tiers''category' => 'Dialers'],
  1107.         ];
  1108.     }
  1109.     /**
  1110.      * @return array
  1111.      */
  1112.     private function getWidgets(): array
  1113.     {
  1114.         return [
  1115.             // Administrator
  1116.             'widget_activity' => ['name' => 'Activity''category' => 'Administrator'],
  1117.             // Collection
  1118.             'widget_collection_percent' => ['name' => 'Collection Percent''category' => 'Collection''legacy' => ['widget_collection']],
  1119.             'widget_collection_past_due' => ['name' => 'Collection Past Due''category' => 'Collection''legacy' => ['widget_collection']],
  1120.             'widget_collection_paid' => ['name' => 'Collection Paid''category' => 'Collection''legacy' => ['widget_collection']],
  1121.             'widget_collection_late_fees' => ['name' => 'Collection Late Fees''category' => 'Collection'],
  1122.             'widget_transactions' => ['name' => 'Transactions''category' => 'Collection''legacy' => ['widget_collectors']],
  1123.             'widget_late_customers' => ['name' => 'Late Customers''category' => 'Collection'],
  1124.             // Service
  1125.             'widget_stage_stats' => ['name' => 'Stage Stats''category' => 'Service'],
  1126.             'widget_completed_stages' => ['name' => 'Completed Stages''category' => 'Service''legacy' => ['widget_stages']],
  1127.             'widget_completed_stage_items' => ['name' => 'Completed Stage Items''category' => 'Service''legacy' => ['widget_stages']],
  1128.             'widget_closed' => ['name' => 'Closed Cases''category' => 'Service'],
  1129.             'widget_closed_avg_hours_worked' => ['name' => 'Closed Cases Avg. Hours Worked''category' => 'Service'],
  1130.             'widget_closed_avg_aging' => ['name' => 'Closed Cases Avg. Aging''category' => 'Service'],
  1131.             'widget_stop_work' => ['name' => 'Stop Work''category' => 'Service'],
  1132.             'widget_tax_returns' => ['name' => 'Completed Tax Returns''category' => 'Service'],
  1133.             'widget_completed_qa' => ['name' => 'Completed QA''category' => 'Service'],
  1134.             'widget_star_rating_avg' => ['name' => 'Star Rating Avg.''category' => 'Service'],
  1135.             // Revenue
  1136.             'widget_scheduled' => ['name' => 'Scheduled''category' => 'Revenue'],
  1137.             'widget_paid' => ['name' => 'Paid''category' => 'Revenue'],
  1138.             'widget_revenue' => ['name' => 'Revenue''category' => 'Revenue'],
  1139.             'widget_stats_1' => ['name' => 'Stats #1''category' => 'Revenue'],
  1140.             'widget_stats_2' => ['name' => 'Stats #2''category' => 'Revenue'],
  1141.             // Sales
  1142.             'widget_leaderboard' => ['name' => 'Leaderboard''category' => 'Sales'],
  1143.             'widget_leads' => ['name' => 'Leads''category' => 'Sales''legacy' => ['widget_totals']],
  1144.             'widget_interviews' => ['name' => 'Interviews''category' => 'Sales''legacy' => ['widget_totals']],
  1145.             'widget_interviews_time' => ['name' => 'Interviews Time''category' => 'Sales''legacy' => ['widget_totals']],
  1146.             'widget_customers' => ['name' => 'Customers''category' => 'Sales''legacy' => ['widget_totals']],
  1147.             'widget_conversion' => ['name' => 'Conversion''category' => 'Sales''legacy' => ['widget_totals']],
  1148.             // Transfer
  1149.             'widget_transfer_total' => ['name' => 'Total''category' => 'Transfer''legacy' => ['widget_totals']],
  1150.             'widget_transfer_percent' => ['name' => 'Percent''category' => 'Transfer'],
  1151.             'widget_transfer_avg_per_hour' => ['name' => 'Avg. Per Hour''category' => 'Transfer'],
  1152.             'widget_transfer_avg_per_user' => ['name' => 'Avg. Per User''category' => 'Transfer'],
  1153.             // Outbound
  1154.             'widget_outbound_sales' => ['name' => 'Sales''category' => 'Outbound''legacy' => ['widget_outbound']],
  1155.             'widget_outbound_service' => ['name' => 'Service''category' => 'Outbound''legacy' => ['widget_outbound_service']],
  1156.         ];
  1157.     }
  1158. }