Enhance Subscriptions, Affiliates, and Software Distribution modules
This commit is contained in:
@@ -127,10 +127,10 @@ class SoftwareManager
|
||||
/**
|
||||
* Check for updates
|
||||
*/
|
||||
public static function check_update($license_key, $slug, $current_version)
|
||||
public static function check_update($license_key, $slug, $current_version, $site_url = null)
|
||||
{
|
||||
// Validate license
|
||||
$license_validation = LicenseManager::validate($license_key);
|
||||
$license_validation = LicenseManager::validate($license_key, $site_url);
|
||||
|
||||
if (!$license_validation['valid']) {
|
||||
return [
|
||||
@@ -255,10 +255,21 @@ class SoftwareManager
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . self::$versions_table;
|
||||
|
||||
return $wpdb->get_results($wpdb->prepare(
|
||||
$results = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT * FROM $table WHERE product_id = %d ORDER BY release_date DESC",
|
||||
$product_id
|
||||
), ARRAY_A);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as &$row) {
|
||||
$decoded_changelog = json_decode($row['changelog'], true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$row['changelog'] = $decoded_changelog;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,6 +319,39 @@ class SoftwareManager
|
||||
return $wpdb->insert_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a version
|
||||
*/
|
||||
public static function update_version($version_id, $product_id, $version, $changelog = '', $set_current = false)
|
||||
{
|
||||
global $wpdb;
|
||||
$table = $wpdb->prefix . self::$versions_table;
|
||||
|
||||
// Reset other current versions if this one is set to current
|
||||
if ($set_current) {
|
||||
$wpdb->update($table, ['is_current' => 0], ['product_id' => $product_id]);
|
||||
}
|
||||
|
||||
// Update version
|
||||
$wpdb->update($table, [
|
||||
'version' => $version,
|
||||
'changelog' => $changelog,
|
||||
'is_current' => $set_current ? 1 : 0,
|
||||
], [
|
||||
'id' => $version_id,
|
||||
'product_id' => $product_id
|
||||
]);
|
||||
|
||||
// Update product meta
|
||||
if ($set_current) {
|
||||
update_post_meta($product_id, '_woonoow_software_current_version', $version);
|
||||
}
|
||||
|
||||
do_action('woonoow/software/version_updated', $version_id, $product_id, $version);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate secure download token
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user