Source of file EcommerceProductVariationTaskDeleteAll.php
Size: 1,954 Bytes - Last Modified: 2021-12-23T10:41:03+00:00
/var/www/docs.ssmods.com/process/src/src/Tasks/EcommerceProductVariationTaskDeleteAll.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | <?php namespace Sunnysideup\EcommerceProductVariation\Tasks; use SilverStripe\Dev\BuildTask; use SilverStripe\ORM\DB; use Sunnysideup\EcommerceProductVariation\Model\Buyables\ProductVariation; use Sunnysideup\EcommerceProductVariation\Model\TypesAndValues\ProductAttributeType; use Sunnysideup\EcommerceProductVariation\Model\TypesAndValues\ProductAttributeValue; class EcommerceProductVariationTaskDeleteAll extends BuildTask { protected $title = 'Deletes all the variations and associated data'; protected $description = 'Deletes ALL variations and all associated data, careful.'; protected $tableArray = [ ProductVariation::class, 'ProductVariation_AttributeValues', 'Product_VariationAttributes', ProductAttributeType::class, ProductAttributeValue::class, ]; public function run($request) { $productVariationArrayID = []; if (empty($_GET['live'])) { $live = false; } else { $live = intval($_GET['live']) === 1 ? true : false; } if ($live) { DB::alteration_message('this is a live task', 'deleted'); } else { DB::alteration_message('this is a test only. If you add a live=1 get variable then you can make it for real ;-)', 'created'); } foreach ($this->tableArray as $table) { $sql = "DELETE FROM \"${table}\""; DB::alteration_message("<pre>DELETING FROM ${table}: <br /><br />" . $sql . '</pre>'); if ($live) { DB::query($sql); } $sql = "SELECT COUNT(ID) FROM \"${table}\""; $count = DB::query($sql)->value(); if ($count === 0) { $style = 'created'; } else { $style = 'deleted'; } DB::alteration_message(' **** COMPLETED, NUMBER OF REMAINING RECORD: ' . $count . ' **** ', $style); } } } |