1. 程式人生 > >大型ECShop安裝搬家升級錯誤問題最全攻略

大型ECShop安裝搬家升級錯誤問題最全攻略

item auth prototype c2c params 同時 return ping 屏蔽

【引子】

最近將ECShop框架網站從租用服務器搬家至阿裏雲,雖然模塊及功能上已經被修改的面目全非了,但基礎部分還在。

在這個過程中遇到了很多的WARNING與ERROR,解決方案如下。

【環境】

服務器環境由PHP5.3+MySQL5.6更新至PHP5.6+MySQL5.7

【數據庫】

利用navicat for mysql工具導入導出,出現異常:Invalid default value for ‘create_time‘,具體可參考上一篇隨筆。http://www.cnblogs.com/eDevelop/p/7081061.html

【後臺】

打開首頁報錯,提示:
Strict standards: Non-static method cls_image::gd_version() should not be called statically in includes\lib_base.php on line 355

return cls_image::gd_version();

對象可以訪問靜態方法,使用的是$p->function(),對象訪問靜態屬性采用p::function()形式。

$cimage=new cls_image();
return $cimage->gd_version();
類似還有:
Strict standards: Non-static method cls_sql_dump::get_random_name() should not be called statically in admin\database.php on line 64
$smarty->assign(‘sql_name‘, cls_sql_dump::get_random_name() . ‘.sql‘);
修改為:
$csdump=new cls_sql_dump($db,$max_size);
$smarty->assign(‘sql_name‘, $csdump->get_random_name() . ‘.sql‘);
嫌麻煩直接找到function get_random_name()函數,前面加個static完事。

個人設置:

Strict standards: Only variables should be passed by reference in includes\cls_template.php on line 422

$tag_sel = array_shift(explode(‘ ‘, $tag));

調用函數傳參錯誤

$p=explode(‘ ‘, $tag);
$tag_sel = array_shift($p);

商品分類:

 Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead inincludes\cls_template.php on line 304
 
return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select(‘\\1‘);", $source);

PHP升級5.5之後,摒棄了preg_replace的/e特性。

return preg_replace_callback("/{([^\}\{\n]*)}/", function($func) { return $this->select($func[1]); }, $source);

問題集中在cls_template中。

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in includes\cls_template.php on line 554
$val = preg_replace("/\[([^\[\]]*)\]/eis", "‘.‘.str_replace(‘$‘,‘\$‘,‘\\1‘)", $val);
修改為:
$val = preg_replace_callback(‘/\[([^\[\]]*)\]/is‘,function ($matches) {return ‘.‘.str_replace(‘$‘,‘\$‘,$matches[1]);},$val);
Deprecated
: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in includes\cls_template.php on line 491 $out = "<?php \n" . ‘$k = ‘ . preg_replace("/(\‘\\$[^,]+)/e" , "stripslashes(trim(‘\\1‘,‘\‘‘));", var_export($t, true)) . ";\n";
修改為:
$out = "<?php " . ‘$k = ‘ . preg_replace_callback("/(\‘\\$[^,] )/" , function($match){return stripslashes(trim($match[1],‘\‘‘));},
var_export($t, true)) . ";\n";
Deprecated
: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in includes\cls_template.php on line 1074 $pattern = ‘/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se‘; $replacement = "‘{include file=‘.strtolower(‘\\1‘). ‘}‘"; $source = preg_replace($pattern, $replacement, $source); 修改為:
$pattern = ‘/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s‘;
$source = preg_replace_callback($pattern, function ($func){return ‘{include file=‘.strtolower($func[1]).‘}‘;},$source);
歷史訂單:查看->配送方式:編輯
Warning: Illegal string offset ‘free_money‘ in admin\order.php on line 3696
使用$shipping[‘configure‘][‘free_money‘]形式,要求$shipping[‘configure‘]為數組,可以引入IF判斷解決 if(is_array($shipping[‘configure‘])){...}
Warning
: number_format() expects parameter 1 to be double, string given in includes\lib_common.php on line 1019
雖然ECShop2.7.3對參數$price進行判斷是否為空,但配送插件裏面的免費額度為0,ec本身的bug導致了$price的值為空值,直接調用number_format出現了錯誤。
在PHP5.3上報錯,但獲取到的應該是一個字符串,所以出錯,應該這樣改:
$price = 0 + $price;//添加這一行,轉換成數值

商店設置:

Strict standards: mktime(): You should be using the time() function instead in admin\sms_url.php on line 31
Strict standards: mktime(): You should be using the time() function instead in admin\shop_config.php on line 32
mktime()方法不帶參數被調用時,會被拋出一個報錯提示。
$auth=mktime();
修改為:
$autu=time();

管理員權限與角色管理:

Warning: join(): Invalid arguments passed in admin\privilege.php on line 602
Warning: Invalid argument supplied for foreach() in admin\privilege.php on line 604
Warning: join(): Invalid arguments passed in admin\role.php on line 217
Warning: Invalid argument supplied for foreach() in admin\role.php on line 219
這裏與上上個錯誤類似,數組類型取值才不會警告。 使用if(is_array($action_group[‘priv‘])){}將join與foreach代碼段包進去。
網上給出方案如下,感覺大同小異。
if(is_array($action_group[‘priv‘])){
$action_group[‘priv‘] = $action_group[‘priv‘];
}else{
$action_group[‘priv‘] = array();
}
自定義導航欄也報錯:
Warning: Illegal string offset ‘cat_name‘ in admin\navigator.php on line 383
if(is_array($val)){...}

角色管理與權限管理:只有checkbox選框,沒有label文字

鎖定privilege_allot.htm與role_info.htm,修改如下:
$lang[$priv.action_code]->$lang.$priv.action_code
$lang[$list.action_code]->$lang.$list.action_code

數據備份:

Strict standards: Redefining already defined constructor for class cls_sql_dump in admin\includes\cls_sql_dump.php on line 90

類似還有支付方式:

Strict Standards: Redefining already defined constructor for class chinabank in includes/modules/payment/chinabank.php on line 85

Strict Standards: Redefining already defined constructor for class paypal_ec in includes/modules/payment/paypal_ec.php on line 96

Strict Standards: Redefining already defined constructor for class shenzhou in includes/modules/payment/shenzhou.php on line 81

Strict Standards: Redefining already defined constructor for class ips in includes/modules/payment/ips.php on line 82

Strict Standards: Redefining already defined constructor for class balance in includes/modules/payment/balance.php on line 79

Strict Standards: Redefining already defined constructor for class alipay in includes/modules/payment/alipay.php on line 85

Strict Standards: Redefining already defined constructor for class tenpay in includes/modules/payment/tenpay.php on line 83

Strict Standards: Redefining already defined constructor for class post in includes/modules/payment/post.php on line 79

Strict Standards: Redefining already defined constructor for class paypal in includes/modules/payment/paypal.php on line 82

Strict Standards: Redefining already defined constructor for class tenpayc2c in includes/modules/payment/tenpayc2c.php on line 83

Strict Standards: Redefining already defined constructor for class cappay in includes/modules/payment/cappay.php on line 81

Strict Standards: Redefining already defined constructor for class bank in includes/modules/payment/bank.php on line 79

Strict Standards: Redefining already defined constructor for class kuaiqian in includes/modules/payment/kuaiqian.php on line 83

Strict Standards: Redefining already defined constructor for class cod in includes/modules/payment/cod.php on line 82

使用和類名相同點函數名作為構造函數是php4時代的寫法,php5時代的構造函數是__construct(),ecshop為了兼容老版本的php,所以采用了上面的寫法。
但是從php5.4開始,對於這樣的兩種寫法同時出現的情況,要求必須__construct()在前,同名函數在後,所以只需要對調兩個函數的位置即可。

如alipay.php,將
    function __construct()
    {
        $this->alipay();
    }
放到
    function alipay()
    {

    }
前面。

首頁廣告管理:

Strict standards: Only variables should be passed by reference in admin\flashplay.php on line 274
傳參時賦值,偷懶了。
set_flash_data($_CFG[‘flash_theme‘], $error_msg = ‘‘);
修改為:
$error_msg = ‘‘ set_flash_data($_CFG[‘flash_theme‘], $error_msg);

後臺翻頁功能失效,彈出 transport.js /run() error:undefined。

FF調試報錯:Uncaught transport.js/parseResult() error: can‘t parse to JSON.

ECShop把AJAX事件和JSON解析的模塊放在common/transport.js之中,在封裝JSON各種方法的同時對object的模型進行了重寫,跟jQuery沖突!

ECShop論壇上提出了一些辦法,不是很好用。

1、首先復制一份 transport.js 改名為 transport.org.js 提供給後臺使用
2、屏蔽掉transport.js裏的toJSON功能,註釋掉行數大概在497-737行之間的內容,從if ( ! Object.prototype.toJSONString)開始
  修改352行為: legalParams = "JSON=" + $.toJSON(params);
  修改408行為:result = $.evalJSON(result);
  屏蔽掉global.js裏的如下代碼(第10-13行):
  Object.prototype.extend = function(object)
  {
    return Object.extend.apply(this, [this, object]);
  }
3、修改index.js文件44行為:var res = $.evalJSON(result);
4、修改common.js文件34行為:Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods), addToCartResponse, ‘POST‘, ‘JSON‘);
  修改850行為
:Ajax.call(‘flow.php?step=add_package_to_cart‘, ‘package_info=‘ + $.toJSON(package_info), addPackageToCartResponse, ‘POST‘, ‘JSON‘);
  修改1056行為
:Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods), addToCartResponse, ‘POST‘, ‘JSON‘); 5、修改compare.js文件49行為: this.data = $.evalJSON(cookieValue);   修改67行為: var obj = $.evalJSON(cookieValue);   修改133行為: document.setCookie("compareItems", $.toJSON(this.data)); 6、修改global.js文件   修改16行函數名 :function $e()   修改114和126行為:var element = $e(element); 7、修改後臺頭部引入transport.js路徑
 admin/templates/pageheader.htm 第9行改為: {insert_scripts files="../js/transport.org.js,common.js"}   admin/templates/menu.htm 第151行改為: {insert_scripts files="../js/global.js,../js/utils.js,../js/transport.org.js"} 8、修改themes/default/library/page_header.lbi文件在{insert_scripts files=‘transport.js,utils.js‘}上面加上:
  {insert_scripts files
=‘jquery.js,jquery.json.js‘}   jquery.json.js下載 9、修改library/comment_list.lbi 188行為:   Ajax.call(‘comment.php‘, ‘cmt=‘ + $.toJSON(cmt), commentResponse, ‘POST‘, ‘JSON‘); 10、修改compare.dwt 20行為:   var obj = $.evalJSON(document.getCookie("compareItems"));   24行: document.setCookie("compareItems", $.toJSON(obj)); 11、修改flow.dwt 138行為:   Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods),collect_to_flow_response, ‘POST‘, ‘JSON‘);   199行: Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods),fittings_to_flow_response, ‘POST‘, ‘JSON‘); 12、修改brand.dwt、brand_list.dwt、category.dwt、exchange_list.dwt、search.dwt文件,增加   {insert_scripts files=‘jquery.js,jquery.json.js‘}   {insert_scripts files=‘common.js,global.js,compare.js‘}
註意:包括其他jquery文件需置頂的dwt文件,jquery.js文件需要在compare.js文件加載前加載

大概思路就是屏蔽ECshop擴展的toJSONString方法,用別的函數代替。

大型ECShop安裝搬家升級錯誤問題最全攻略