恢复我的 WordPress WooCommerce 数据库后,我的虚拟产品的所有可下载文件都消失了。
我已查询 wp_postmeta
表,发现 _downloadable_files
条目仍然存在,并且我已验证表中的 URL 仍然有效。
但是,这些文件不再在订单电子邮件中显示为链接,不再出现在我的帐户页面中,也不再出现在可下载文件部分中编辑产品中的产品数据。
据我所知,唯一有效的修复方法是手动重新输入所有文件。
我正在使用 Apache2 和 MySQL。这些文件存储在为 WordPress 提供服务的同一台 Apache 服务器上。
我正在尝试将开发数据库从不同的开发服务器复制到新环境 我正在尝试找到一种有效的方法来执行此操作,而无需手动重新输入所有可下载文件。
最佳答案
深入研究这一点,我认为问题在于 WooCommerce 正在生成有关可下载文件 URL 的 MD5,该 URL 不会从一台服务器传输到另一台服务器。
查看 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 的 WooCommerce REST API PHP client 使用 WooCommerce REST API 重新加载可下载文件。
<?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();
关于php - Woocommerce:数据库恢复后可下载文件消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29635202/