-
Notifications
You must be signed in to change notification settings - Fork 11
/
magento-profile
executable file
·106 lines (91 loc) · 3.07 KB
/
magento-profile
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
#!/usr/bin/env php
<?php
//
// Update the environment for this Magento installation. Useful for
// situations where core_config_data may have incorrect environment information.
//
// Usage:
// magento-profile
//
// @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");
$profiles = explode("\n", `ls $support_dir/profiles | grep -v .sql`);
if($server->argc == 2) {
$key = $server->argv[1];
if(!in_array($key, $profiles)) {
print_error("Sorry, '$key' isn't a valid profile. Try again.\n");
exit;
}
} else {
print "\nStore profiles\n";
foreach($profiles as $profile) {
printf("%-10s\n", $profile);
}
print "\n";
$default = basename($magento);
if(!in_array($default, $profiles)) { $default = null; }
$key = user_array_choice("Select a profile to load for this store", $profiles, $default);
}
require_once("$support_dir/profiles/$key");
print "Loading site profile for $key.\n";
$query_stack = array();
// change config data
foreach($profile['config'] as $key => $value) {
$query_stack[] = "update core_config_data set value='$value' where path='$key'";
}
// alter properties of CMS pages (like changing layout)
if(isset($profile['cms_pages'])) {
foreach($profile['cms_pages'] as $identifier => $values) {
$keys = array();
foreach($values as $key => $value) {
$keys[] = "$key = '$value'";
}
$keys = implode(", ", $keys);
$query_stack[] = "update cms_page set $keys where identifier = '$identifier'";
}
}
// delete all design changes
if(isset($profile['delete_designs']) && $profile['delete_designs']) {
$query_stack[] = "delete from design_change";
}
// disable caches
if(isset($profile['cache_all'])) {
$on = $profile['cache_all'] ? "1" : "0";
$query_stack[] = "update core_cache_option set value = $on";
}
print "Running profile transactions.\n";
start_db_transaction();
$query = "";
try {
foreach($query_stack as $query) {
$res = mysql_query($query);
if(!$res) { throw new Exception(mysql_error()); }
}
commit_db_transaction();
} catch(Exception $e) {
print $query;
rollback_db_transaction();
print_error("There was an error during the database commit (".$e->getMessage()."). Couldn't load site profile.");
}
if(isset($profile['sql'])) {
print "Running profile SQL loaders.\n";
foreach($profile['sql'] as $file) {
if(!file_exists("$support_dir/profiles/$file")) { continue; }
db_load_file("$support_dir/profiles/$file");
print " Loaded $file.\n";
}
print " Done.\n";
}
function putdocs() {
return array(
"Load profile data for an installation, including DB params.",
"Usage: magento-profile [KEY]",
"", "Useful for after you load a DB dump from a production system and",
"need to change the hostname and payment info from that dump. Also",
"supports .sql files as loaders for haphazard data.",
);
}