0

I wrote a section in UpgradeData.php to insert and delete some values in tables directory_country_region_name and directory_country_region. Code below,

if (version_compare($context->getVersion(), "1.0.6", "<")) {
    $connection = $setup->getConnection();
    $disallowed = implode(',',[6,7,8,9,10,11,17,30,50]);
    $caFrLocalization = array(array('fr_CA',66,'Alberta'),
        array('fr_CA',67,'Colombie-Britannique'),
        array('fr_CA',68,'Manitoba'),
        array('fr_CA',69,'Terre-Neuve-et-Labrador'),
        array('fr_CA',70,'Nouveau-Brunswick'),
        array('fr_CA',71,'Nouvelle-Écosse'),
        array('fr_CA',72,'Territoires du Nord-Ouest'),
        array('fr_CA',73,'Nunavut'),
        array('fr_CA',74,'Ontario'),
        array('fr_CA',75,'Île-du-Prince-Édouard'),
        array('fr_CA',76,'Québec'),
        array('fr_CA',77,'Saskatchewan'),
        array('fr_CA',78,'Yukon'));

    // Add Canadian localized regions
    $connection->insertArray($connection->getTableName('directory_country_region_name'),array('locale', 'region_id', 'name'),$caFrLocalization);

    // Remove extra US states
    $connection->delete($connection->getTableName('directory_country_region_name'),['region_id IN (?)'=>$disallowed]);
    $connection->delete($connection->getTableName('directory_country_region'),['region_id IN (?)'=>$disallowed]);
}

And module.xml,

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Project_Ecommerce" setup_version="1.0.7"/>
</config>

When I deploy this to the local Magento environment the changes are made as expected.

However when I deploy to the Magento Cloud I do not see the results of this code executing.


This is the script I use to deploy these changes to Magento Local,

rm -rf var/di var/generation
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy en_CA fr_CA -f
php bin/magento weltpixel:less:generate
php bin/magento cache:flush
sudo chmod 777 var/cache

On the Magento Cloud I just deploy the changes with a git push.

1

You should change the version compare to the following:

if (version_compare($context->getVersion(), "1.0.7", "<")) {

It's because the current version is 1.0.6, in your original version compare, it return false result so your script do not run.

!!BUT!!

Check the record on table setup_module before you apply the fix. If the record show the version is 1.0.7 already, you have to either

  • Change the module version to 1.0.8

OR

  • Run SQL to change it back to 1.0.6, then rerun setup:upgrade
  • I changed the version in version_compare to 1.0.7 and the version in setup_module to 1.0.6 and I can see the code executed during deployment on the cloud, thanks! Only the two delete calls did not execute which I assume is another issue. – oldrustybucket Oct 23 '18 at 16:15
0
if (version_compare($context->getVersion(), "2.0.2", "<")) {
   $connection = $setup->getConnection();

   $ukLocalization = array(array('GB','IF,'Berkshire'));

   // Add UK localized regions
   $connection->insertArray($connection->getTableName('directory_country_region'),array('country_id', 'code', 'default_name'),$ukLocalization);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.