function run($request) { $count = 0; $array = EcommerceCountry::get_country_dropdown(); $allowedArray = EcommerceConfig::get("EcommerceCountry", "allowed_country_codes"); foreach ($array as $code => $name) { $ecommerceCountry = EcommerceCountry::get()->Filter(array("Code" => Convert::raw2sql($code)))->First(); if ($ecommerceCountry) { //do nothing $count++; } else { DB::alteration_message("adding {$code} to Ecommerce Country", "created"); $ecommerceCountry = EcommerceCountry::create(); $ecommerceCountry->Code = $code; } if ($allowedArray && count($allowedArray)) { if (in_array($code, $allowedArray)) { //do nothing $ecommerceCountry->DoNotAllowSales = 0; } else { $ecommerceCountry->DoNotAllowSales = 1; } } $ecommerceCountry->Name = $name; $ecommerceCountry->write(); } DB::alteration_message("Created / Checked {$count} Ecommerce Countries", "edited"); }