Skip to content

Instantly share code, notes, and snippets.

@opengeek
Created December 18, 2017 20:04
Show Gist options
  • Save opengeek/321df54f236af4dd8fc126c257e7cdfc to your computer and use it in GitHub Desktop.
Save opengeek/321df54f236af4dd8fc126c257e7cdfc to your computer and use it in GitHub Desktop.
<?php
$tstart = microtime(true);
set_time_limit(0);
require 'config.core.php';
require MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = modX::getInstance();
$modx->initialize('mgr');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');
$resourceGroupName = "Default";
$modx->log(modX::LOG_LEVEL_INFO, "Adding all resources to resource group {$resourceGroupName}");
try {
$iterator = $modx->getIterator('modResource');
foreach ($iterator as $resource) {
if (!$resource->isMember($resourceGroupName)) {
$resource->joinGroup($resourceGroupName);
}
}
} catch (Exception $e) {
$tend = microtime(true);
$totalTime= sprintf("%2.4f seconds", ($tend - $tstart));
$modx->log(modX::LOG_LEVEL_ERROR, "Failed adding resources to resource group {$resourceGroupName} in {$totalTime}: {$e->getMessage()}");
}
$tend = microtime(true);
$totalTime= sprintf("%2.4f seconds", ($tend - $tstart));
$modx->log(modX::LOG_LEVEL_INFO, "Added all resources to resource group {$resourceGroupName} in {$totalTime}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment