Content:
- 1. Upgrade source code
- 2. Cách fix bug
- 3. Migrate data
- 4. Tham khảo
1. Update source code
Hiện
tại tài liệu này hướng dẫn update source code lên magento
1.9.1.0
1.1. Chuẩn bị trước khi update source code:
+
Tắt cache
+
Backup một số file thông tin của site: index.php, .htaccess,
app/etc/local.xml
1.2. Các cách update source code:
Có
3 cách update source code:
- Copy đè code
- Bằng command line
Cách
1 và cách 2 chỉ làm được ở bản PHP 5.3, vì ở các
cách này, các gói sẽ được download về về và giải nén
bởi function PHP, PHP > 5.3 không giản nén được các gói
này,
1.3. Chi tiết Update source code
1.3.1. Copy đè
Download
bộ source code từ trang chủ Magento, giải nén và đè vào
source code Magento phiên bản cũ.
1.3.2: Command line
Cách
này không update trực tiếp lên 1.9.1.0, mà phải qua phiên
bản 1.4.2.0 (nếu phiên bản hiện tại của magento <
1.4.2.0)
-
Lên 1.4.2.0:
./pear
mage-setup
./pear
upgrade -f magento-core/Mage_All_Latest-stable
./mage
mage-setup
./mage
sync
*
Nếu lỗi xảy ra:
+
Fatal error: Call to a member function getPosition() on a non-object
in
D:\xampp\htdocs\farmstore\app\code\core\Mage\Page\Block\Template\Links.php
on line 112
Nguyên
nhân là do cấu trúc của 1.4.2.0 thay đổi so với 1.4.1.1,
function này được sử dụng trong việc gọi các block link
trên homepage
Khắc
phục:
+
http://kb.magenting.com/content/21/84/en/magento-fatal-error-call-to-a-member-function-getposition-on-a-non-object-in-app-code-core-mage-page-block-template-linksphp-on-line-112.html
-
Lên 1.9.1.0:
./mage
list-upgrades
./mage
config-set preferred_state stable
./mage
install http://connect20.magentocommerce.com/community
Mage_All_Latest –force
*
Nếu lỗi xảy ra:
+
Install: Unsupported resource type -> Nguyên nhân là do phiên
bản php hiện tại không thể thao tác trên các gói dữ
liệu tải về.
Cách
khắc phục:
+
Chạy command sang bản PHP thấp hơn (PHP 5.3)
+
Tìm đến file theo đường dẫn
root/downloader/lib/Mage/Archive/Tar.php
Thay
thế
const
FORMAT_PARSE_HEADER =
'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix/a12closer';
Bằng
const
FORMAT_PARSE_HEADER =
‘Z100name/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/Z8checksum/Z1type/Z100symlink/Z6magic/Z2version/Z32uname/Z32gname/Z8devmajor/Z8devminor/Z155prefix/Z12closer';
*
Sau đó, load trang bất kỳ để Magento cập nhật script.
2. Fix bug
- Sau khi update source thành công, sẽ gặp khá nhiều lỗi, đa số lỗi là do theme. Theme xây dựng dựa trên bản version cũ, nhưng khi nâng cấp, function thay đổi, theme vẫn dùng các function cũ nên gặp lỗi.
Cách fix: so sánh code, rút ra sự khác biệt
luồng, tên phương thức rồi fix cho hợp lý. Xem lại các
class, function rewite ở version cũ rồi chỉnh lại cho hợp
lý.
3. Migrate data.
Sau
khi update source code, nếu như database lớn, lúc load trang để
cập nhật script thất bại (thường gặp khi upgrade
Magento < 1.6 lên Magento > 1.7), thì phải xóa bớt data.
Sự
thay đổi lớn nhất là ở các bảng order, nên chỉ cần
xóa order là có thể upgrade được.
Chi
tiết migrate data - Chỉ thử nghiệm ở phiên bản 1.4.1.1
lên 1.9.1.0
3.1. Migrate order
- Dump dữ liệu các order của Magento cũ
Dùng
câu lệnh mysql:
mysqldump
-uroot -p --no-data=false --no-create-info=false
--extended-insert=true --complete-insert=false --skip-tz-utc --force
--add-drop-table=false --comments=false --create-options=true
--dump-date=false --lock-tables=false --add-locks=false
--compact=false --disable-keys=false DBNAME_14 sales_flat_quote
sales_flat_quote_item sales_flat_quote_address
sales_flat_quote_address_item sales_flat_quote_item_option
sales_flat_quote_payment sales_flat_quote_shipping_rate
sales_flat_order sales_flat_order_grid sales_flat_order_item
sales_flat_order_address sales_flat_order_payment
sales_flat_order_status_history sales_flat_invoice
sales_flat_invoice_grid sales_flat_invoice_item
sales_flat_invoice_comment sales_flat_shipment
sales_flat_shipment_grid sales_flat_shipment_item
sales_flat_shipment_comment sales_flat_shipment_track
sales_flat_creditmemo sales_flat_creditmemo_grid
sales_flat_creditmemo_item sales_flat_creditmemo_comment
sales_recurring_profile sales_recurring_profile_order sales_order_tax
sales_order_aggregated_created sales_shipping_aggregated
sales_shipping_aggregated_order sales_invoiced_aggregated
sales_invoiced_aggregated_order sales_refunded_aggregated
sales_refunded_aggregated_order sales_payment_transaction
sales_bestsellers_aggregated_daily
sales_bestsellers_aggregated_monthly
sales_bestsellers_aggregated_yearly sales_billing_agreement
sales_billing_agreement_order > db_file_14_order.sql
Thay
thế tham số phù hợp: username, db name
- Delete dữ liệu ở các bảng order
Dùng
câu lệnh mysql:
SET
FOREIGN_KEY_CHECKS=0;
TRUNCATE
sales_flat_quote;
TRUNCATE
sales_flat_quote_item;
TRUNCATE
sales_flat_quote_address;
TRUNCATE
sales_flat_quote_address_item;
TRUNCATE
sales_flat_quote_item_option;
TRUNCATE
sales_flat_quote_payment;
TRUNCATE
sales_flat_quote_shipping_rate;
TRUNCATE
sales_flat_order;
TRUNCATE
sales_flat_order_grid;
TRUNCATE
sales_flat_order_item;
TRUNCATE
sales_flat_order_address;
TRUNCATE
sales_flat_order_payment;
TRUNCATE
sales_flat_order_status_history;
TRUNCATE
sales_flat_invoice;
TRUNCATE
sales_flat_invoice_grid;
TRUNCATE
sales_flat_invoice_item;
TRUNCATE
sales_flat_invoice_comment;
TRUNCATE
sales_flat_shipment;
TRUNCATE
sales_flat_shipment_grid;
TRUNCATE
sales_flat_shipment_item;
TRUNCATE
sales_flat_shipment_comment;
TRUNCATE
sales_flat_shipment_track;
TRUNCATE
sales_flat_creditmemo;
TRUNCATE
sales_flat_creditmemo_grid;
TRUNCATE
sales_flat_creditmemo_item;
TRUNCATE
sales_flat_creditmemo_comment;
TRUNCATE
sales_recurring_profile;
TRUNCATE
sales_recurring_profile_order;
TRUNCATE
sales_order_tax;
TRUNCATE
sales_order_aggregated_created;
TRUNCATE
sales_shipping_aggregated;
TRUNCATE
sales_shipping_aggregated_order;
TRUNCATE
sales_invoiced_aggregated;
TRUNCATE
sales_invoiced_aggregated_order;
TRUNCATE
sales_refunded_aggregated;
TRUNCATE
sales_refunded_aggregated_order;
TRUNCATE
sales_payment_transaction;
TRUNCATE
sales_bestsellers_aggregated_daily;
TRUNCATE
sales_bestsellers_aggregated_monthly;
TRUNCATE
sales_bestsellers_aggregated_yearly;
TRUNCATE
sales_billing_agreement;
TRUNCATE
sales_billing_agreement_order;
SET
FOREIGN_KEY_CHECKS=1;
- Reload page để Magento cập nhật script. Lúc này đã có Magento 1.9.1.0 nhưng không có order.
- Import file “db_file_14_order.sql” đã dump order từ trước vào 1 database khác.
- Xử lý database này để các dữ liệu của order tương thích với 1.9.1.0
Dùng
câu lệnh mysql:
SET
FOREIGN_KEY_CHECKS=0;
ALTER
TABLE `sales_flat_creditmemo` CHANGE
`base_shipping_hidden_tax_amount` `base_shipping_hidden_tax_amnt`
DECIMAL(12,4) NULL DEFAULT NULL COMMENT 'Base Shipping Hidden Tax
Amount';
ALTER
TABLE `sales_flat_creditmemo_item` CHANGE
`base_weee_tax_applied_row_amount` `base_weee_tax_applied_row_amnt`
DECIMAL(12,4) NULL DEFAULT NULL COMMENT 'Base Weee Tax Applied Row
Amnt';
ALTER
TABLE `sales_flat_invoice_item` CHANGE
`base_weee_tax_applied_row_amount` `base_weee_tax_applied_row_amnt`
DECIMAL(12,4) NULL DEFAULT NULL COMMENT 'Base Weee Tax Applied Row
Amnt';
ALTER
TABLE `sales_flat_order` CHANGE `forced_do_shipment_with_invoice`
`forced_shipment_with_invoice` SMALLINT(5) UNSIGNED NULL DEFAULT NULL
COMMENT 'Forced Do Shipment With Invoice', CHANGE
`payment_authorization_expiration` `payment_auth_expiration` INT(11)
NULL DEFAULT NULL COMMENT 'Payment Authorization Expiration', CHANGE
`base_shipping_hidden_tax_amount` `base_shipping_hidden_tax_amnt`
DECIMAL(12,4) NULL DEFAULT NULL COMMENT 'Base Shipping Hidden Tax
Amount';
ALTER
TABLE `sales_flat_order_item` CHANGE
`base_weee_tax_applied_row_amount` `base_weee_tax_applied_row_amnt`
DECIMAL(12,4) NULL DEFAULT NULL COMMENT 'Base Weee Tax Applied Row
Amnt';
ALTER
TABLE `sales_flat_quote_item` CHANGE
`base_weee_tax_applied_row_amount` `base_weee_tax_applied_row_amnt`
DECIMAL(12,4) NULL DEFAULT NULL COMMENT 'Base Weee Tax Applied Row
Amnt';
ALTER
TABLE `sales_flat_quote_address` CHANGE
`base_shipping_hidden_tax_amount` `base_shipping_hidden_tax_amnt`
DECIMAL(12,5) NULL DEFAULT NULL COMMENT 'Base Shipping Hidden Tax
Amount';
ALTER
TABLE `sales_flat_shipment_track` CHANGE `number` `track_number` TEXT
CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT
'Number';
ALTER
TABLE `sales_flat_invoice` CHANGE `base_shipping_hidden_tax_amount`
`base_shipping_hidden_tax_amnt` DECIMAL(12,4) NULL DEFAULT NULL
COMMENT 'Base Shipping Hidden Tax Amount';
SET
FOREIGN_KEY_CHECKS=1;
- Dump database này, chỉ dump dữ liệu, không dump cấu trúc.
Dùng
câu lệnh mysql dump, thêm tham số: --no-create-info=true
- Import file này (data order) vào database Magento 1.9.1.0. Lúc này, đã có bản hoàn chỉnh Magento 1.9.1.0
3.2. Migrate All
- Nếu muốn, có thể migrate cả product, category, và customer. Quy trình tương tự 3.1. Các bảng trong database:
Customer:
TRUNCATE
customer_address_entity;
TRUNCATE
customer_address_entity_datetime;
TRUNCATE
customer_address_entity_decimal;
TRUNCATE
customer_address_entity_int;
TRUNCATE
customer_address_entity_text;
TRUNCATE
customer_address_entity_varchar;
TRUNCATE
customer_entity;
TRUNCATE
customer_entity_datetime;
TRUNCATE
customer_entity_decimal;
TRUNCATE
customer_entity_int;
TRUNCATE
customer_entity_text;
TRUNCATE
customer_entity_varchar;
Product:
TRUNCATE
TABLE `catalog_product_bundle_option`;
TRUNCATE
TABLE `catalog_product_bundle_option_value`;
TRUNCATE
TABLE `catalog_product_bundle_selection`;
TRUNCATE
TABLE `catalog_product_entity`;
TRUNCATE
TABLE `catalog_product_entity_datetime`;
TRUNCATE
TABLE `catalog_product_entity_decimal`;
TRUNCATE
TABLE `catalog_product_entity_gallery`;
TRUNCATE
TABLE `catalog_product_entity_int`;
TRUNCATE
TABLE `catalog_product_entity_media_gallery`;
TRUNCATE
TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE
TABLE `catalog_product_entity_text`;
TRUNCATE
TABLE `catalog_product_entity_tier_price`;
TRUNCATE
TABLE `catalog_product_entity_varchar`;
TRUNCATE
TABLE `catalog_product_link`;
TRUNCATE
TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE
TABLE `catalog_product_link_attribute_int`;
TRUNCATE
TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE
TABLE `catalog_product_option`;
TRUNCATE
TABLE `catalog_product_option_price`;
TRUNCATE
TABLE `catalog_product_option_title`;
TRUNCATE
TABLE `catalog_product_option_type_price`;
TRUNCATE
TABLE `catalog_product_option_type_title`;
TRUNCATE
TABLE `catalog_product_option_type_value`;
TRUNCATE
TABLE `catalog_product_super_attribute`;
TRUNCATE
TABLE `catalog_product_super_attribute_label`;
TRUNCATE
TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE
TABLE `catalog_product_super_link`;
TRUNCATE
TABLE `catalog_product_enabled_index`;
TRUNCATE
TABLE `catalog_product_website`;
Category:
TRUNCATE
TABLE `catalog_category_entity`;
TRUNCATE
TABLE `catalog_category_entity_datetime`;
TRUNCATE
TABLE `catalog_category_entity_decimal`;
TRUNCATE
TABLE `catalog_category_entity_int`;
TRUNCATE
TABLE `catalog_category_entity_text`;
TRUNCATE
TABLE `catalog_category_entity_varchar`;
TRUNCATE
TABLE `catalog_category_product`;
TRUNCATE
TABLE `catalog_category_product_index`;
*** Note: Đây là tool lấy tất cả dữ
liệu trong bảng product, customer, order từ 1 ngày cố định
(nhập trong trình duyệt, định dạng: “yyyy-mm-dd
HH:ii:ss”) đến ngày hiện tại, rồi xuất ra file .sql
Mở
file và thay đổi thông tin host, username, password của
database.
4. Tham khảo
* Hãy thực hiện tất cả các bước trên,
khi site chạy được rồi, mới reindex data.
- Phần migrate order chỉ làm chi tiết đối với Magento 1.4.1.1 lên Magento 1.9.1.0. Nếu muốn làm được ở các version khác nhau, hãy so sánh cấu trúc database giữa 2 phiên bản. Có thể so sánh từng bảng một (bằng tay), hoặc so sánh bằng tool: https://github.com/phindmarsh/mysql-dbcompare.
(h)
ReplyDelete