php - Woocommerce: downloadable files disappear after database restore -


after restoring wordpress woocommerce database, downloadable files virtual products have disappeared.

i have queried wp_postmeta table , see _downloadable_files entries still there , have verified url's in table still valid.

however, files no longer appear links in order emails, no longer appear in my account page, , no longer appear in downloadable files section in product data in edit product.

the fix know works manually re-enter files.

i'm using apache2 , mysql. files stored on same apache server serving wordpress.

i trying copy development database different development server new environment , trying find efficient way without having manually re-enter downloadable files.

digging think issue woocommerce generating md5 of downloadable file url not transfer 1 server another.

looking @ data in wordpress wp_postmeta table, see

mysql> select post_id,meta_value wordpress.wp_postmeta 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 fccc91f867cc071737bea5433d1c3181 value somehow not recognized valid when database transferred new host.

to work around issue, wrote php script read database , reload downloadable files using 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 own consumer key here $consumer_secret = 'cs_secretxxx'; // add own consumer secret here $store_url = 'http://123456789/'; // add home url store want connect here  // initialize 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 wordpress.wp_postmeta 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(); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -