Woocommerce:数据库还原后,可下载文件消失 [英] Woocommerce: downloadable files disappear after database restore

查看:74
本文介绍了Woocommerce:数据库还原后,可下载文件消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还原我的WordPress WooCommerce数据库后,我的虚拟产品的所有可下载文件都消失了.

我查询了wp_postmeta表,发现_downloadable_files条目仍然存在,并且我已验证表中的URL仍然有效.

但是,文件不再显示为订购电子邮件中的链接,不再显示在我的帐户页面中,也不再显示在"编辑产品中的产品数据.

我知道的唯一解决方法是手动重新输入所有文件.

我正在使用Apache2和MySQL.这些文件存储在提供WordPress的同一Apache服务器上.

我正在尝试将开发数据库从其他开发服务器复制到新环境 并且正在尝试找到一种有效的方法来执行此操作,而不必手动重新输入所有可下载的文件.

解决方案

研究这个问题,我认为问题在于WooCommerce正在生成MD5,其中包含有关可下载文件URL的信息,而该文件不会从一台服务器传输到另一台服务器. /p>

我在看WordPress wp_postmeta表中的数据,

mysql> SELECT post_id,meta_value FROM wordpress.wp_postmeta where meta_key='_downloadable_files';
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| post_id | meta_value                                                                                                                                                                                            |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|      33 | a:1:{s:32:"fccc91f867cc071737bea5433d1c3181";a:2:{s:4:"name";s:3:"fox";s:4:"file";s:61:"http://_123456789_.com/wp-content/uploads/2015/03/fox.png";}}  

我的猜测是,当数据库转移到新主机时,fccc91f867cc071737bea5433d1c3181值不知为何不合法.

要解决此问题,我编写了一个PHP脚本来读取数据库,然后通过Gerhard Potgieter的

After restoring my WordPress WooCommerce database, all the Downloadable Files for my virtual products have disappeared.

I have queried the wp_postmeta table and see that the _downloadable_files entries are still there and I have verified that the URL's in the table are still valid.

However, the files no longer appear as links in order emails, no longer appear in the My Account page, and no longer appear in the Downloadable Files section in the Product Data in the Edit Product.

The only fix that I know works is to manually re-enter all the files.

I'm using Apache2 and MySQL. The files are stored on the same Apache server that is serving WordPress.

I am trying to copy a development database from a different development server to a new environment and am trying to find an efficient way to do this without having to manually re-enter all the downloadable files.

解决方案

Digging into this I think that the issue is that WooCommerce is generating an MD5 of something about the Downloadable File URL which does not transfer from one server to another.

Looking at data in the WordPress wp_postmeta table, I see

mysql> SELECT post_id,meta_value FROM wordpress.wp_postmeta where meta_key='_downloadable_files';
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| post_id | meta_value                                                                                                                                                                                            |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|      33 | a:1:{s:32:"fccc91f867cc071737bea5433d1c3181";a:2:{s:4:"name";s:3:"fox";s:4:"file";s:61:"http://_123456789_.com/wp-content/uploads/2015/03/fox.png";}}  

My guess is that the fccc91f867cc071737bea5433d1c3181 value is somehow not recognized as valid when the database is transferred to a new host.

To work around the issue, I wrote a PHP script to read the database and then reload the Downloadable Files using the WooCommerce REST API via Gerhard Potgieter's WooCommerce REST API PHP client.

<?php

error_reporting( E_ALL );
ini_set( 'display_errors', 'On' );
require_once "class-wc-api-client.php";

$consumer_key = 'ck_examplexxx'; // Add your own Consumer Key here
$consumer_secret = 'cs_secretxxx'; // Add your own Consumer Secret here
$store_url = 'http://123456789/'; // Add the home URL to the store you want to connect to here

// Initialize the class
$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );

$servername = "_dbhost_";
$username = "wordpress";
$password = "__password__";
$dbname = "wordpress";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT post_id,meta_value FROM wordpress.wp_postmeta where meta_key='_downloadable_files'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    $product_id = $row["post_id"];
    $meta_value = $row["meta_value"];
    preg_match("/.+\:\"(http:\/\/.+\/wp-content\/uploads\/.+\/.+\/(.+)\..+)\".+/", $meta_value, $m);
    print_r( $wc_api->update_product( $product_id, '{
          "product": {
            "downloads": [
              {
                "name": "' . $m[2] . '",
                "file": "' . $m[1] . '"
              }
            ]
          }
        }'));
  }
} else {
  echo "0 results";
}
$conn->close();

这篇关于Woocommerce:数据库还原后,可下载文件消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆