Skip to content

Fix MagicPreview errors when extra is not installed #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 3.x
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 10, 2025

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 Copilot AI changed the title [WIP] MagicPreview errors Fix MagicPreview errors when extra is not installed Jul 10, 2025
@Copilot Copilot AI requested a review from Mark-H July 10, 2025 14:26
Copilot finished work on behalf of Mark-H July 10, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MagicPreview errors
2 participants