doutong7216 2015-04-14 18:51
浏览 59
已采纳

Woocommerce:数据库恢复后可下载的文件消失

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.

  • 写回答

2条回答 默认 最新

  • drctyr2869 2015-04-14 23:07
    关注

    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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?