Skip to content

Commit

Permalink
Minor tweaks and rebuild package
Browse files Browse the repository at this point in the history
- Add descriptions to new plugins
- Set site_start setting for hub context
  • Loading branch information
hugopeek committed Jan 17, 2018
1 parent feee7b3 commit 04289e7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 13 deletions.
4 changes: 3 additions & 1 deletion _build/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3773,11 +3773,13 @@
},
{
"name": "setResourceIDs",
"description": "Looks for resource IDs of Romanesco pages that were built by the Romanesco Backyard package. When a resource is found, the referring system setting is updated with the corresponding ID. Disabled by default.",
"category": "c_settings",
"events": []
},
{
"name": "updateStyling",
"name": "UpdateStyling",
"description": "Gets triggered when theme settings are changed in the ClientConfig CMP. It changes Semantic UI variables and triggers a new SUI build in the background. Requires NPM and the EXEC function to be available on the server.",
"category": "c_settings",
"events": [
"ClientConfig_ConfigChange"
Expand Down
4 changes: 3 additions & 1 deletion _build/src/07_computations/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"plugins": [
{
"name": "setResourceIDs",
"description": "Looks for resource IDs of Romanesco pages that were built by the Romanesco Backyard package. When a resource is found, the referring system setting is updated with the corresponding ID. Disabled by default.",
"category": "c_settings",
"events": []
},{
"name": "updateStyling",
"name": "UpdateStyling",
"description": "Gets triggered when theme settings are changed in the ClientConfig CMP. It updates certain Semantic UI variables and triggers a new SUI build in the background. Requires NPM and the EXEC function to be available on the server.",
"category": "c_settings",
"events": ["ClientConfig_ConfigChange"]
}
Expand Down
Binary file modified _packages/romanesco-0.11.3-pl.transport.zip
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ function setResourceID($systemSetting, $contextKey, $alias)
}
}

if (!function_exists('setContextSetting')) {
function setContextSetting($contextSetting, $contextKey, $alias)
{
global $modx;

// Get the resource
$query = $modx->newQuery('modResource');
$query->where(array(
'context_key' => $contextKey,
'alias' => $alias,
));
$query->select('id');
$resourceID = $modx->getValue($query->prepare());

if (!$resourceID) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not find resource ID for: ' . $alias);
return;
}

// Update context setting
$setting = $modx->getObject('modContextSetting', array(
'context_key' => $contextKey,
'key' => $contextSetting
));

if ($setting) {
$setting->set('value', $resourceID);
$setting->save();
} else {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not find context setting with key: ' . $contextSetting);
}

return;
}
}

// Find resources and set correct IDs
setResourceID('romanesco.cta_container_id', 'global','call-to-actions');
setResourceID('romanesco.global_backgrounds_id', 'global','backgrounds');
Expand All @@ -57,5 +93,8 @@ function setResourceID($systemSetting, $contextKey, $alias)
setResourceID('romanesco.pattern_container_id', 'hub','patterns');
setResourceID('romanesco.backyard_container_id', 'hub','backyard');

// Set site_start for Project Hub context
setContextSetting('site_start', 'hub','dashboard');

break;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
<?php
/**
* UpdateStyling
*
* This plugin is activated when certain theme settings are changed in the
* ClientConfig CMP.
*
* It changes some variables used by Semantic UI to generate the CSS and it also
* triggers a new SUI build in the background. This requires NPM to be available
* on the server, as well as the exec function.
*
* NB! ENABLING THE EXEC FUNCTION ON YOUR SERVER IS A POTENTIAL SECURITY RISK!
* Please make sure your server and MODX install are sufficiently hardened
* before enabling this functionality. You can always update the SUI styling and
* run the build process manually, so there's no harm done if this plugin can't
* be activated.
*
* It also generates favicon images if a logo badge is provided. This relies on
* a few Gulp dependencies (see package.json) and the Real Favicon service:
* https://realfavicongenerator.net/favicon/gulp
*/

// Check if exec function is available on the server
if(@exec('echo EXEC') !== 'EXEC'){
$modx->log(modX::LOG_LEVEL_ERROR, '[UpdateStyling] Exec function not available');
Expand Down Expand Up @@ -60,9 +81,6 @@ function ($key) {
$updatedSettings = array_diff($savedSettingsTheme, $currentSettingsTheme);
$deletedSettings = array_diff($currentSettingsTheme, $savedSettingsTheme);

//$modx->log(modX::LOG_LEVEL_ERROR, 'updated settings: ' . print_r($updatedSettings));
//$modx->log(modX::LOG_LEVEL_ERROR, 'deleted settings: ' . print_r($deletedSettings));

$output = array();

// Regenerate styling elements if theme settings were updated or deleted
Expand All @@ -73,12 +91,6 @@ function ($key) {
$modx->getCacheManager()->delete('',array(xPDO::OPT_CACHE_KEY => 'resource'));
}

//$command = '/home/hugo/.npm-global/bin/gulp --gulpfile ' . escapeshellcmd($modx->getOption('assets_path')) . 'semantic/gulpfile.js build-css > ./logs/romanesco.log 2>./logs/error.log &';
//$command = 'gulp --gulpfile ' . escapeshellcmd($modx->getOption('assets_path')) . 'semantic/gulpfile.js build-css > ' .escapeshellcmd($modx->getOption('core_path')) . 'cache/logs/romanesco.log 2>' .escapeshellcmd($modx->getOption('core_path')) . 'cache/logs/romanesco.log &';

// Create directory for logs (if it doesn't exist already)
//exec('cd ' . escapeshellcmd($modx->getOption('core_path')) . ' && mkdir -p logs 2>&1', $output);

// Terminate any existing gulp processes
$killCommand = "ps aux | grep '[g]ulpfile " . $modx->getOption('assets_path') . "semantic/gulpfile.js' | awk '{print $2}'";
exec(
Expand All @@ -93,14 +105,12 @@ function ($key) {
' --gulpfile ' . escapeshellcmd($modx->getOption('assets_path')) . 'semantic/gulpfile.js' .
' > ' .escapeshellcmd($modx->getOption('core_path')) . 'cache/logs/romanesco.log' .
' 2>' .escapeshellcmd($modx->getOption('core_path')) . 'cache/logs/romanesco.log &',
//' 2>&1 | tee -a ' .escapeshellcmd($modx->getOption('core_path')) . 'cache/logs/romanesco.log',
$output,
$return_css
);

// Update favicon if a new logo image was provided
if (array_key_exists('logo_badge_path', $updatedSettings)) {
//$modx->log(modX::LOG_LEVEL_ERROR, '[UpdateStyling] Logo badge was changed');
$logoBadgePath = $modx->getOption('base_path') . $savedSettingsTheme['logo_badge_path'];

exec(
Expand Down

0 comments on commit 04289e7

Please sign in to comment.