forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mautic#7596 from d-code-ltd/multiselect-as-text
Store multiselect values as text with maximum length of 65535
- Loading branch information
Showing
3 changed files
with
85 additions
and
4 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,77 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2019 Mautic Contributors. All rights reserved | ||
* @author Mautic | ||
* | ||
* @link http://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
class Version20190724110039 extends AbstractMauticMigration | ||
{ | ||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function up(Schema $schema) | ||
{ | ||
// Change multiselect custom fields from VARCHAR(255) to TEXT | ||
$qb = $this->connection->createQueryBuilder(); | ||
$qb->select('lf.alias') | ||
->from($this->prefix.'lead_fields', 'lf') | ||
->where( | ||
$qb->expr()->eq('lf.type', $qb->expr()->literal('multiselect')) | ||
); | ||
$multiselectFields = $qb->execute()->fetchAll(); | ||
|
||
$leadsTable = $schema->getTable($this->prefix.'leads'); | ||
|
||
if (!empty($multiselectFields)) { | ||
foreach ($multiselectFields as $key => $field) { | ||
if ($leadsTable->hasColumn($field['alias'])) { | ||
if ($leadsTable->hasIndex("{$field['alias']}_search")) { | ||
$this->addSql("DROP INDEX `{$field['alias']}_search` ON `{$this->prefix}leads`"); | ||
} | ||
$this->addSql("ALTER TABLE `{$this->prefix}leads` CHANGE `{$field['alias']}` `{$field['alias']}` TEXT"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function down(Schema $schema) | ||
{ | ||
// Change multiselect custom fields from VARCHAR(255) to TEXT | ||
$qb = $this->connection->createQueryBuilder(); | ||
$qb->select('lf.alias') | ||
->from($this->prefix.'lead_fields', 'lf') | ||
->where( | ||
$qb->expr()->eq('lf.type', $qb->expr()->literal('multiselect')) | ||
); | ||
$multiselectFields = $qb->execute()->fetchAll(); | ||
|
||
$leadsTable = $schema->getTable($this->prefix.'leads'); | ||
|
||
if (!empty($multiselectFields)) { | ||
foreach ($multiselectFields as $key => $field) { | ||
if ($leadsTable->hasColumn($field['alias'])) { | ||
$this->addSql("ALTER TABLE `{$this->prefix}leads` CHANGE `{$field['alias']}` `{$field['alias']}` VARCHAR(255)"); | ||
if (!$leadsTable->hasIndex("{$field['alias']}_search")) { | ||
$this->addSql("CREATE INDEX `{$field['alias']}_search` ON `{$this->prefix}leads`(`{$field['alias']}`)"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |