1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class EcommerceProductVariationTaskDeleteAll extends BuildTask |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
protected $title = "Deletes all the variations and associated data"; |
6
|
|
|
|
7
|
|
|
protected $description = "Deletes ALL variations and all associated data, careful."; |
8
|
|
|
|
9
|
|
|
protected $tableArray = array( |
10
|
|
|
"ProductVariation", |
11
|
|
|
"ProductVariation_AttributeValues", |
12
|
|
|
"Product_VariationAttributes", |
13
|
|
|
"ProductAttributeType", |
14
|
|
|
"ProductAttributeValue" |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
public function run($request) |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$productVariationArrayID = array(); |
|
|
|
|
20
|
|
View Code Duplication |
if (empty($_GET["live"])) { |
|
|
|
|
21
|
|
|
$live = false; |
22
|
|
|
} else { |
23
|
|
|
$live = intval($_GET["live"]) == 1 ? true : false; |
24
|
|
|
} |
25
|
|
|
if ($live) { |
26
|
|
|
DB::alteration_message("this is a live task", "deleted"); |
27
|
|
|
} else { |
28
|
|
|
DB::alteration_message("this is a test only. If you add a live=1 get variable then you can make it for real ;-)", "created"); |
29
|
|
|
} |
30
|
|
|
foreach ($this->tableArray as $table) { |
31
|
|
|
$sql = "DELETE FROM \"$table\""; |
32
|
|
|
DB::alteration_message("<pre>DELETING FROM $table: <br /><br />".$sql."</pre>"); |
33
|
|
|
if ($live) { |
34
|
|
|
DB::query($sql); |
35
|
|
|
} |
36
|
|
|
$sql = "SELECT COUNT(ID) FROM \"$table\""; |
37
|
|
|
$count = DB::query($sql)->value(); |
38
|
|
|
if ($count == 0) { |
39
|
|
|
$style = "created"; |
40
|
|
|
} else { |
41
|
|
|
$style = "deleted"; |
42
|
|
|
} |
43
|
|
|
DB::alteration_message(" **** COMPLETED, NUMBER OF REMAINING RECORD: ".$count." **** ", $style); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
class EcommerceProductVariationTaskDeleteAll_EXT extends Extension |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
private static $allowed_actions = array( |
|
|
|
|
51
|
|
|
"ecommerceproductvariationtaskdeletevariations" => true |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
//NOTE THAT updateEcommerceDevMenuConfig adds to Config options |
55
|
|
|
//but you can als have: updateEcommerceDevMenuDebugActions |
56
|
|
|
public function updateEcommerceDevMenuRegularMaintenance($buildTasks) |
57
|
|
|
{ |
58
|
|
|
$buildTasks[] = "ecommerceproductvariationtaskdeleteall"; |
59
|
|
|
return $buildTasks; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function ecommerceproductvariationtaskdeleteall($request) |
63
|
|
|
{ |
64
|
|
|
$this->owner->runTask("ecommerceproductvariationtaskdeleteall", $request); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.