Skip to content

Commit

Permalink
Merge pull request #136 from modmore/issue135-fix-snapshot-errors
Browse files Browse the repository at this point in the history
Prevent package resolver from creating an initial delta for an object if one already exists
  • Loading branch information
muzzwood authored Aug 16, 2024
2 parents 5351494 + 0c93c48 commit f9b002e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/* define version */
define('PKG_NAME', 'VersionX');
define('PKG_NAMESPACE', 'versionx');
define('PKG_VERSION', '3.1.1');
define('PKG_VERSION', '3.1.2');
define('PKG_RELEASE', 'pl');

/* load modx */
Expand Down
43 changes: 30 additions & 13 deletions _build/resolvers/setupoptions.resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
use modmore\VersionX\Types\TV;
use modmore\VersionX\Types\Type;

if (isset($object) && isset($object->xpdo)) {
/**
* @var \modX|\MODX\Revolution\modX $modx
* @var \xPDOTransport|\xPDO\Transport\xPDOTransport $object
* @var array $options
*/
if (isset($object->xpdo)) {
$modx = $object->xpdo;
}
if (!isset($modx)) {
Expand All @@ -36,34 +41,37 @@

$modx->log(modX::LOG_LEVEL_INFO,'Starting snapshot process for selected objects...');

if (isset($options['vx_snapshot_resources']) && !empty($options['vx_snapshot_resources'])) {
if (!empty($options['vx_snapshot_resources'])) {
createInitialDelta($versionX, modResource::class, new Resource($versionX), 'Resource');
}

if (isset($options['vx_snapshot_templates']) && !empty($options['vx_snapshot_templates'])) {
if (!empty($options['vx_snapshot_templates'])) {
createInitialDelta($versionX, modTemplate::class, new Template($versionX), 'Template');
}

if (isset($options['vx_snapshot_chunks']) && !empty($options['vx_snapshot_chunks'])) {
if (!empty($options['vx_snapshot_chunks'])) {
createInitialDelta($versionX, modChunk::class, new Chunk($versionX), 'Chunk');
}

if (isset($options['vx_snapshot_snippets']) && !empty($options['vx_snapshot_snippets'])) {
if (!empty($options['vx_snapshot_snippets'])) {
createInitialDelta($versionX, modSnippet::class, new Snippet($versionX), 'Snippet');
}

if (isset($options['vx_snapshot_plugins']) && !empty($options['vx_snapshot_plugins'])) {
if (!empty($options['vx_snapshot_plugins'])) {
createInitialDelta($versionX, modPlugin::class, new Plugin($versionX),'Plugin');
}

if (isset($options['vx_snapshot_tmplvars']) && !empty($options['vx_snapshot_tmplvars'])) {
if (!empty($options['vx_snapshot_tmplvars'])) {
createInitialDelta($versionX, modTemplateVar::class, new TV($versionX), 'TV');
}

break;
}

/**
* Attempts to create an initial delta for each object of the given type (resource, snippet etc.)
* If a delta already exists from a previous install, skip and continue.
*
* @param VersionX $versionX
* @param string $class
* @param Type $type
Expand All @@ -74,17 +82,26 @@ function createInitialDelta(VersionX $versionX, string $class, Type $type, strin
{
global $modx;

$modx->log(modX::LOG_LEVEL_INFO,"Iterating over {$name}s and storing snapshots..");
$modx->log(modX::LOG_LEVEL_INFO,"Iterating over {$name}s and creating initial snapshots..");

$count = 0;
foreach ($modx->getIterator($class) as $object) {
if ($versionX->deltas()->createDelta($object->get('id'), $type)) {
$count++;
}
else {
$modx->log(modX::LOG_LEVEL_WARN,"Error creating snapshot for {$name} {$object->get('id')}");
// Only create a delta if none currently exist for the given object
if (!$modx->getObject(vxDelta::class, [
'principal_package' => 'core',
'principal_class' => $class,
'principal' => $object->get('id'),
])) {
// Create an initial delta for this object
if (!$versionX->deltas()->createDelta($object->get('id'), $type)) {
$modx->log(modX::LOG_LEVEL_WARN,"Error creating snapshot for {$name} {$object->get('id')}");
continue;
}
}

// Add to count if either we didn't encounter an error
$count++;

if (is_int($count / 25)) {
$modx->log(modX::LOG_LEVEL_INFO,"Checked {$count} {$name}s so far.");
}
Expand Down
6 changes: 6 additions & 0 deletions core/components/versionx/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
VersionX 3.1.2-pl
-----------------
Released on 2024-

- Prevent initial delta being created by package resolver if created previously

VersionX 3.1.1-pl
-----------------
Released on 2024-06-28
Expand Down
2 changes: 1 addition & 1 deletion core/components/versionx/docs/version.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

const VERSIONX_VERSION = '3.1.1';
const VERSIONX_VERSION = '3.1.2';
const VERSIONX_RELEASE = 'pl';
const VERSIONX_FULLVERSION = VERSIONX_VERSION . '-' . VERSIONX_RELEASE;

0 comments on commit f9b002e

Please sign in to comment.