forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
6 changed files
with
148 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mautic\SmsBundle\Event; | ||
|
||
use Symfony\Component\Form\FormBuilder; | ||
|
||
class SmsPropertiesEvent extends \Symfony\Contracts\EventDispatcher\Event | ||
{ | ||
private array $fields = []; | ||
|
||
public function __construct(private FormBuilder $formBuilder, private array $data) | ||
{ | ||
} | ||
|
||
public function getFormBuilder(): FormBuilder | ||
{ | ||
return $this->formBuilder; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function addField(string $child, string $type = null, array $options = []): void | ||
{ | ||
$this->fields[] = [ | ||
'child' => $child, | ||
'type' => $type, | ||
'options' => $options, | ||
]; | ||
} | ||
|
||
public function getFields(): array | ||
{ | ||
return $this->fields; | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mautic\SmsBundle\Form\Type; | ||
|
||
use Mautic\SmsBundle\Event\SmsPropertiesEvent; | ||
use Mautic\SmsBundle\SmsEvents; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class SmsPropertiesType extends AbstractType | ||
{ | ||
private EventDispatcherInterface $dispatcher; | ||
|
||
public function __construct(\Symfony\Contracts\EventDispatcher\EventDispatcherInterface $dispatcher) | ||
{ | ||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$event = new SmsPropertiesEvent($builder, $options['data'] ?? []); | ||
$this->dispatcher->dispatch($event, SmsEvents::SMS_PROPERTIES); | ||
|
||
foreach ($event->getFields() as $formField) { | ||
$builder->add($formField['child'], $formField['type'], $formField['options']); | ||
} | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mautic\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\Exception\SkipMigration; | ||
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration; | ||
|
||
final class Version20240209104703 extends AbstractMauticMigration | ||
{ | ||
public function preUp(Schema $schema): void | ||
{ | ||
$smsTable = $schema->getTable(MAUTIC_TABLE_PREFIX.'sms_messages'); | ||
if ($smsTable->hasColumn('properties')) { | ||
throw new SkipMigration('Schema includes this migration'); | ||
} | ||
} | ||
|
||
/** | ||
* @throws \Doctrine\DBAL\Schema\SchemaException | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
$smsTable = $schema->getTable(MAUTIC_TABLE_PREFIX.'sms_messages'); | ||
if (!$smsTable->hasColumn('properties')) { | ||
$this->addSql("ALTER TABLE {$this->prefix}sms_messages ADD properties LONGTEXT NOT NULL COMMENT '(DC2Type:json)'"); | ||
} | ||
} | ||
} |