zen cart - 對多個站點批量實施後臺操作

如果你有N個站,所有的網站都要進行一系列的後臺操作,那麼如果一個個去登陸然後操作是繁瑣而且浪費時間的。下面的這個腳本是用來開關支付方式並設定順序,當然裏面沒有涉及到設置商戶和返回鏈接這幾個動作。需要進一步完善。

 

<?php
/*
@author george zheng <[email protected]>
@date 2012.03.12
@usage php scriptname 'key of info to use'
*/
$info = array(
    'f1' => array('root','xxxxx'),
    'f2' => array('root','xxxxx'),
    'f3' => array('root','xxxxx'),
    'f4' => array('root','xxxxx'),
    'f5' => array('root','Xxxxx'),
);
if ($argc < 2) {
    die('Pls secify the mysql profile to use'."\n");
} else {
    $dbuser = $info[$argv[1]][0];
    $dbpass = $info[$argv[1]][1];
}
set_time_limit(0);
$link = @mysql_connect('localhost', $dbuser, $dbpass)
  or die("Database connnected error \n");

try{
  $db_list = @mysql_list_dbs($link) or die("Can not get database list \n");

} catch(Exception $ex) {
  echo "Database connnected error \n";
  exit;
}
$count = 0;
while ($row = mysql_fetch_object($db_list)) {
    $db = $row->Database;
	if(table_exists($link, $db, 'configuration')){
	//echo $db."\n";continue;
	    $count++;
		mysql_select_db($db, $link);
		//mysql_select_db('uggsnorg_onorge', $link);
		$sql = "update configuration set configuration_value='2' where configuration_key='MODULE_PAYMENT_PAYEASE_SORT_ORDER'";
		sql_query($sql, $link);
		$sql = "update configuration set configuration_value='1' where configuration_key='MODULE_PAYMENT_IPS_SORT_ORDER'";
		sql_query($sql, $link);
		$sql = "update configuration set configuration_value='True' where configuration_key='MODULE_PAYMENT_IPS_STATUS' OR configuration_key='MODULE_PAYMENT_PAYEASE_STATUS'";
		sql_query($sql, $link);
		$sql = "update configuration set configuration_value=0 WHERE configuration_key='MODULE_PAYMENT_PAYEASE_ZONE'";
		sql_query($sql, $link);
		$result = mysql_query("select configuration_value from `configuration` where configuration_key = 'MODULE_PAYMENT_INSTALLED';");

		$payment_keys = '';
		while($row = mysql_fetch_array($result)){
						$payment_keys = $row['configuration_value'];
		}
		$payment_arr = explode(";",$payment_keys);

		$install_payment = "";
		$pay_arr = array();
		foreach($payment_arr as $k=>$val){
						if ($val=='payease.php') {
										$pay_arr[1]='payease.php';
						} elseif ($val=='ips.php') {
										$pay_arr[0]='ips.php';
						}
		}
		ksort($pay_arr);
		$install_payment = implode(";",$pay_arr);
		sql_query("update `configuration` set configuration_value='$install_payment' where configuration_key='MODULE_PAYMENT_INSTALLED'",$link);
		echo "\n" . $db .' updated successfully' . "\n";
	} else {
		echo $db.' has no configuration table' . "\n";
	}
}

mysql_close($link);
echo 'Total ' . $count . ' databases updated successfully!';

function sql_query($query, $link)
{
   if (empty($query)) {
        die('Sql can not be empty' . "\n");
   }
   $result = mysql_query($query, $link);
        // Check result
        // This shows the actual query sent to MySQL, and the error. Useful for debugging.
   if (!$result) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        die($message);
   } else {
     echo 'query successfully!' . "\n" . $query . "\n";
   }
}

function table_exists($link,$db,$table) {

    if (empty($table)) {
        die('No table name provided to check');
    }
    $tables = array();
    $sql = "SHOW TABLES FROM $db";
    $result = mysql_query($sql, $link);

    if (!$result) {
        echo "DB Error, could not list tables\n";
        echo 'MySQL Error: ' . mysql_error();
        exit;
    }

    while ($row = mysql_fetch_row($result)) {
        $tables[] = $row[0];
    }
    return in_array('configuration', $tables);
//    return FALSE;
//    return TRUE;
}

?>


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章