You've already forked wc-licensed-product
Fix version upload handling and add better error logging
- Fix VersionManager::createVersion() to handle null attachment_id properly - Add product type validation in AJAX version handler - Add database error logging for debugging - Improve meta box visibility logic for licensed products - Add known bug note to CLAUDE.md Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,7 @@ This project is proudly **"vibe-coded"** using Claude.AI - the entire codebase w
|
|||||||
|
|
||||||
### Known Bugs
|
### Known Bugs
|
||||||
|
|
||||||
_No known bugs at this time._
|
- Version uploads not appearing in list (under investigation - may require plugin reactivation to ensure database tables exist)
|
||||||
|
|
||||||
### Version 0.0.10
|
### Version 0.0.10
|
||||||
|
|
||||||
|
|||||||
@@ -46,14 +46,23 @@ final class VersionAdminController
|
|||||||
*/
|
*/
|
||||||
public function addVersionsMetaBox(): void
|
public function addVersionsMetaBox(): void
|
||||||
{
|
{
|
||||||
add_meta_box(
|
global $post;
|
||||||
'wc_licensed_product_versions',
|
|
||||||
__('Product Versions', 'wc-licensed-product'),
|
// Only add meta box for licensed products or new products
|
||||||
[$this, 'renderVersionsMetaBox'],
|
if ($post && $post->post_type === 'product') {
|
||||||
'product',
|
$product = wc_get_product($post->ID);
|
||||||
'normal',
|
// Show for licensed products or new products (where type might be selected later)
|
||||||
'high'
|
if (!$product || $product->is_type('licensed') || $post->post_status === 'auto-draft') {
|
||||||
);
|
add_meta_box(
|
||||||
|
'wc_licensed_product_versions',
|
||||||
|
__('Product Versions', 'wc-licensed-product'),
|
||||||
|
[$this, 'renderVersionsMetaBox'],
|
||||||
|
'product',
|
||||||
|
'normal',
|
||||||
|
'high'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,6 +260,16 @@ final class VersionAdminController
|
|||||||
wp_send_json_error(['message' => __('This version already exists.', 'wc-licensed-product')]);
|
wp_send_json_error(['message' => __('This version already exists.', 'wc-licensed-product')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify product exists and is of type licensed
|
||||||
|
$product = wc_get_product($productId);
|
||||||
|
if (!$product) {
|
||||||
|
wp_send_json_error(['message' => __('Product not found.', 'wc-licensed-product')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$product->is_type('licensed')) {
|
||||||
|
wp_send_json_error(['message' => __('This product is not a licensed product.', 'wc-licensed-product')]);
|
||||||
|
}
|
||||||
|
|
||||||
$newVersion = $this->versionManager->createVersion(
|
$newVersion = $this->versionManager->createVersion(
|
||||||
$productId,
|
$productId,
|
||||||
$version,
|
$version,
|
||||||
@@ -260,7 +279,12 @@ final class VersionAdminController
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!$newVersion) {
|
if (!$newVersion) {
|
||||||
wp_send_json_error(['message' => __('Failed to create version.', 'wc-licensed-product')]);
|
global $wpdb;
|
||||||
|
$errorMessage = __('Failed to create version.', 'wc-licensed-product');
|
||||||
|
if (!empty($wpdb->last_error)) {
|
||||||
|
error_log('WC Licensed Product: DB error - ' . $wpdb->last_error);
|
||||||
|
}
|
||||||
|
wp_send_json_error(['message' => $errorMessage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json_success([
|
wp_send_json_success([
|
||||||
|
|||||||
@@ -105,23 +105,31 @@ class VersionManager
|
|||||||
$parsed = ProductVersion::parseVersion($version);
|
$parsed = ProductVersion::parseVersion($version);
|
||||||
|
|
||||||
$tableName = Installer::getVersionsTable();
|
$tableName = Installer::getVersionsTable();
|
||||||
$result = $wpdb->insert(
|
|
||||||
$tableName,
|
// Build data and formats arrays, handling null values properly
|
||||||
[
|
$data = [
|
||||||
'product_id' => $productId,
|
'product_id' => $productId,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'major_version' => $parsed['major'],
|
'major_version' => $parsed['major'],
|
||||||
'minor_version' => $parsed['minor'],
|
'minor_version' => $parsed['minor'],
|
||||||
'patch_version' => $parsed['patch'],
|
'patch_version' => $parsed['patch'],
|
||||||
'release_notes' => $releaseNotes,
|
'release_notes' => $releaseNotes,
|
||||||
'download_url' => $downloadUrl,
|
'download_url' => $downloadUrl,
|
||||||
'attachment_id' => $attachmentId,
|
'is_active' => 1,
|
||||||
'is_active' => 1,
|
];
|
||||||
],
|
$formats = ['%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d'];
|
||||||
['%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d']
|
|
||||||
);
|
// Only include attachment_id if it's set
|
||||||
|
if ($attachmentId !== null && $attachmentId > 0) {
|
||||||
|
$data['attachment_id'] = $attachmentId;
|
||||||
|
$formats[] = '%d';
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $wpdb->insert($tableName, $data, $formats);
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
|
// Log error for debugging
|
||||||
|
error_log('WC Licensed Product: Failed to create version - ' . $wpdb->last_error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user