-
Notifications
You must be signed in to change notification settings - Fork 11
/
magento-test-expunge-data
executable file
·122 lines (102 loc) · 3.41 KB
/
magento-test-expunge-data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env php
<?php
//
// Clear all test data from the system.
//
// @author Joseph Mastey <joseph.mastey@gmail.com>
// @author $Author$
// @version $Id$
// @copyright Copyright (c) JRM Ventures LLC, 2010-
require_once("lib/base.php");
require_once("lib/db.php");
$sqlsts = array();
$purges = array();
$edition = get_edition();
if(user_yesno("Purge sales order / quote data?")) {
$purges[] = "Sales orders";
if(0 == strcmp("community", $edition)) {
$sqlsts[] = "delete from sales_order";
$sqlsts[] = "delete from sales_order_entity";
} else {
$sqlsts[] = "delete from sales_flat_order";
}
$sqlsts[] = "delete from sales_flat_order_item";
$sqlsts[] = "delete from sales_flat_quote";
if(user_yesno("Reset order increment?")) {
$increment = user_text("What should sales order increment be reset to", "100000000");
$sqlsts[] = "update eav_entity_store set increment_last_id = '$increment' where entity_type_id = (select entity_type_id from eav_entity_type where entity_type_code = 'order')";
}
}
if(user_yesno("Purge review data?")) {
$purges[] = "Product reviews";
$sqlsts[] = "delete from review";
$sqlsts[] = "delete from review_entity_summary";
}
if(user_yesno("Purge customer data?")) {
$purges[] = "Customer data";
$sqlsts[] = "delete from customer_entity";
}
if(user_yesno("Purge newsletter data?")) {
print "\n";
if(user_yesno("Purge newsletter templates?")) {
$purges[] = "Newsletter templates";
$sqlsts[] = "delete from newsletter_template";
}
if(user_yesno("Purge newsletter subscribers?")) {
$purges[] = "Newsletter subscribers";
$sqlsts[] = "delete from newsletter_subscriber";
}
if(user_yesno("Purge newsletter queue?")) {
$purges[] = "Newsletter queue";
$sqlsts[] = "delete from newsletter_queue";
}
print "\n";
}
if(user_yesno("Purge catalog data?")) {
$purges[] = "Catalog data";
$sqlsts[] = "delete from catalog_product_entity";
$sqlsts[] = "delete from catalog_category_entity where level > 1";
}
if(user_yesno("Purge search data?")) {
$purges[] = "Catalog search data";
$sqlsts[] = "delete from catalogsearch_query";
}
if(user_yesno("Purge tag data?")) {
$purges[] = "Tag data";
$sqlsts[] = "delete from tag_relation";
if(user_yesno("Purge all product tags?")) {
$purges[] = "Product tags";
$sqlsts[] = "delete from tag_relation";
$sqlsts[] = "delete from tag_summary";
} else {
$sqlsts[] = "update tag_summary set customers = 0, products = 0, uses = 0, historical_uses = 0, popularity = 0";
}
}
print "\nPurges to be completed:\n";
foreach($purges as $purge) {
print "* $purge\n";
}
print "\n";
if(!user_yesno("Delete data from the database?")) {
exit;
}
start_db_transaction();
try {
foreach($sqlsts as $sqlst) {
print "$sqlst\n";
$res = mysql_query($sqlst);
if(!$res) { throw new Exception(mysql_error()); }
}
commit_db_transaction();
print "Cleared test data.\n\n";
} catch( Exception $e ) {
print "Exception detected: ".$e->getMessage()."\n";
rollback_db_transaction();
print "Failed to expunge test data.\n";
}
function putdocs() {
return array(
"Clear all test data from the system.",
"Usage: magento-test-expunge-data",
);
}