|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Dynamic\FoxyStripe\ORM; |
| 4 | + |
| 5 | +use Dynamic\FoxyStripe\Model\FoxyStripeSetting; |
| 6 | +use SilverStripe\Forms\CheckboxField; |
| 7 | +use SilverStripe\Forms\FieldList; |
| 8 | +use SilverStripe\Forms\HeaderField; |
| 9 | +use SilverStripe\Forms\LiteralField; |
| 10 | +use SilverStripe\Forms\ReadonlyField; |
| 11 | +use SilverStripe\Forms\TextField; |
| 12 | +use SilverStripe\ORM\DataExtension; |
| 13 | + |
| 14 | +/** |
| 15 | + * Class SiteConfigMigration |
| 16 | + * |
| 17 | + * Apply this DataExtension to SiteConfig and hit Save. Data will be migrated to FoxyStripeSetting |
| 18 | + * via the onAfterWrite() function. |
| 19 | + * |
| 20 | + * @package Dynamic\FoxyStripe\ORM |
| 21 | + */ |
| 22 | +class SiteConfigMigration extends DataExtension |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @var array |
| 26 | + */ |
| 27 | + private static $db = array( |
| 28 | + 'StoreName' => 'Varchar(255)', |
| 29 | + 'StoreKey' => 'Varchar(60)', |
| 30 | + 'MultiGroup' => 'Boolean', |
| 31 | + 'ProductLimit' => 'Int', |
| 32 | + 'CartValidation' => 'Boolean', |
| 33 | + 'MaxQuantity' => 'Int', |
| 34 | + 'CustomSSL' => 'Boolean', |
| 35 | + 'RemoteDomain' => 'Varchar(255)', |
| 36 | + ); |
| 37 | + |
| 38 | + /** |
| 39 | + * |
| 40 | + */ |
| 41 | + public function onAfterWrite() |
| 42 | + { |
| 43 | + parent::onAfterWrite(); |
| 44 | + |
| 45 | + $config = FoxyStripeSetting::current_foxystripe_setting(); |
| 46 | + |
| 47 | + $config->StoreName = $this->owner->StoreName; |
| 48 | + $config->StoreKey = $this->owner->StoreKey; |
| 49 | + $config->MultiGroup = $this->owner->MultiGroup; |
| 50 | + $config->ProductLimit = $this->owner->ProductLimit; |
| 51 | + $config->CartValidation = $this->owner->CartValidation; |
| 52 | + $config->MaxQuantity = $this->owner->MaxQuantity; |
| 53 | + $config->CustomSSL = $this->owner->CustomSSL; |
| 54 | + $config->RemoteDomain = $this->owner->RemoteDomain; |
| 55 | + |
| 56 | + $config->write(); |
| 57 | + } |
| 58 | +} |
0 commit comments