VersionX icon indicating copy to clipboard operation
VersionX copied to clipboard

Fix MagicPreview errors when extra is not installed

Open Copilot opened this issue 7 months ago • 0 comments

This PR addresses the issue where VersionX generates frequent error messages in MODX logs when the MagicPreview extra is not installed.

Problem

When MagicPreview is not installed, VersionX was attempting to load the MagicPreview service without first checking if the required path exists, causing MODX to log errors:

[2025-07-10 13:59:18] (ERROR @ /var/web/public_html/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 667) Could not load class: MagicPreview from magicpreview
[2025-07-10 13:59:18] (ERROR @ /var/web/public_html/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 1273) Problem getting service magicpreview, instance of class MagicPreview, from path /var/web/public_html/core/components/magicpreview/model/magicpreview/

Solution

Added file_exists() checks before attempting to load the MagicPreview service in two locations:

  1. VersionX::magicPreviewLoaded() method - Added path existence check before calling getService()
  2. Preview processor initialization - Added similar check for consistency

Changes

// Before
if (!$magicPreview = $this->modx->getService('magicpreview', 'MagicPreview', $path)) {
    return false;
}

// After  
if (!file_exists($path) || !$magicPreview = $this->modx->getService('magicpreview', 'MagicPreview', $path)) {
    return false;
}

Impact

  • Before: MODX logs errors when MagicPreview extra is not installed
  • After: No errors logged, graceful degradation when MagicPreview is unavailable
  • Compatibility: Fully backward compatible - no changes when MagicPreview is installed

The fix is minimal and surgical, adding only the necessary path checks to prevent error logging while preserving all existing functionality.

Fixes #150.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Jul 10 '25 14:07 Copilot