Skip to content

Commit

Permalink
fix "Assets" file class in MODX 3
Browse files Browse the repository at this point in the history
  • Loading branch information
matdave committed Aug 19, 2024
1 parent 4dce6c5 commit 5bfae7b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions _build/resolvers/resolve.mediasources.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:
// check modx version
if (empty($modx->version)) {
$modx->getVersionData();
}
$version = (int) $modx->version['version'];
if ($version > 2) {
$sourceClass = \MODX\Revolution\Sources\modMediaSource::class;
$fileClass = '\\MODX\\Revolution\\Sources\\modFileMediaSource';
} else {
$sourceClass = 'sources.modMediaSource';
$fileClass = 'sources.modFileMediaSource';
}
/** @var modMediaSource[] $mediaSources */
$mediaSources = $modx->getIterator('sources.modMediaSource');
$mediaSources = $modx->getIterator($sourceClass);

foreach ($mediaSources as $mediaSource) {
$properties = $mediaSource->getProperties();
Expand Down Expand Up @@ -40,15 +52,14 @@
}

/** @var modMediaSource $assetsMS */
$assetsMS = $modx->getObject('sources.modMediaSource', ['name' => 'Assets']);
$assetsMS = $modx->getObject($sourceClass, ['name' => 'Assets']);
if (!$assetsMS) {
$assetsPath = $modx->getOption('assets_path');
$assetsUrl = $modx->getOption('assets_url');
$basePath = $modx->getOption('base_path');
$baseUrl = $modx->getOption('base_url');

$assetsMS = $modx->newObject('sources.modFileMediaSource');
$assetsMS->set('class_key', 'sources.modFileMediaSource');
$assetsMS = $modx->newObject($fileClass);
$assetsMS->set('name', 'Assets');
$assetsMS->set('description', 'Assets');

Expand Down

0 comments on commit 5bfae7b

Please sign in to comment.