...
$eventName = $modx->event->name;
switch($eventName) {
case 'OnFormsInstall':
$modx->log(modX::LOG_LEVEL_INFO,'id: '.$resource->get('id').' | '.'pagetitle: '.$resource->get('pagetitle').' | '.'mode: '.$mode);
break;
}
... 'newSystemEvents' => array( 'OnMyEvent1' => array( 'name' => 'OnFormsInstall', 'groupname' => 'FormsInstall', 'service' => 1, ), ), ...
... 'elements' => array( 'plugins' => array( 'FormsInstall' => array( 'category' => 'FormsInstall', 'description' => '', 'static' => true, 'static_file' => 'assets/plugins/FormsInstall/FormsInstall.plugin.php', 'events' => array( 'OnFormsInstall' => array( 'priority' => '0', /* priority of the event -- 0 is highest priority */ 'group' => 'plugins', /* should generally be set to 'plugins' */ ), ), ), ), 'chunks' => array( ...
...
$resource->save(); // AUTO-GENERATED BY MYCOMPONENT
// CUSTOM CODE
$resourceId = $resource->get('id');
$pagetitle = $resource->get('pagetitle');
$result = $modx->invokeEvent('OnFormsInstall',array(
'mode' => 'new',
'resource' => $resource,
'id' => $resourceId,
));
$modx->log(modX::LOG_LEVEL_INFO,'id: '.$resourceId.' | '.'pagetitle: '.$pagetitle);
...
$fields = array(
'id' => $id,
'pagetitle' => 'My Page',
'alias' => 'my-page',
'published' => '1',
// etc.
);
$modx->runProcessor('resource/update', $fields);
<?php
if (!function_exists('checkFields')) {
function checkFields($required, $objectFields) {
global $modx;
$fields = explode(',', $required);
foreach ($fields as $field) {
if (! isset($objectFields[$field])) {
$modx->log(modX::LOG_LEVEL_ERROR, '[Forms Resolver] Missing field: ' . $field);
return false;
}
}
return true;
}
}
if($object->xpdo) {
$modx =& $object->xpdo;
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:
$intersects = array (
0 => array (
'pagetitle' => 'Forms',
'parent' => '0',
'template' => 'Default Template [12]',
),
1 => array (
'pagetitle' => 'Business Account',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
2 => array (
'pagetitle' => 'Business ACH',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
3 => array (
'pagetitle' => 'Business Advice',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
4 => array (
'pagetitle' => 'Business Loan',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
5 => array (
'pagetitle' => 'Business Payroll',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
6 => array (
'pagetitle' => 'Solutions Cart',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
7 => array (
'pagetitle' => 'Business Services Request',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
8 => array (
'pagetitle' => '100% Satisfaction',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
9 => array (
'pagetitle' => 'Relationship Rewards Login',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
10 => array (
'pagetitle' => 'Credit Dispute',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
11 => array (
'pagetitle' => 'UCF Alumni',
'parent' => 'Forms',
'template' => 'Default Template [12]',
),
);
if (is_array($intersects)) {
$modx->log(modX::LOG_LEVEL_INFO,'<br />Updating Resources:');
foreach ($intersects as $k => $fields) {
/* make sure we have all fields */
if (! checkFields('pagetitle,parent,template', $fields)) {
continue;
}
$resource = $modx->getObject('modResource', array('pagetitle' => $fields['pagetitle']));
if (! $resource) {
continue;
}
$resourceId = $resource->get('id');
$pagetitle = $resource->get('pagetitle');
$fields['id'] = $resourceId;
$fields['context_key'] = 'mgr';
$response = $modx->runProcessor('resource/update',$fields);
if ($response->isError()) {
$modx->log(MODX_LOG_LEVEL_INFO,'<pre>'.print_r($response->getMessage(),true).'</pre>');
continue;
}
$docArray = $response->getObject();
$modx->log(MODX_LOG_LEVEL_INFO,'The resource "'.$docArray['pagetitle'].' was updated with ID '.$docArray['id']);
}
$modx->log(modX::LOG_LEVEL_INFO,'<br />');
}
break;
case xPDOTransport::ACTION_UNINSTALL:
break;
}
}
return true;
Console running... Attempting to install package with signature: forms-2015.03.10-pl Package found...now preparing to install. Grabbing package workspace... Workspace environment initiated, now installing package... Attempting to preserve files at [hidden for privacy] Updating Resources: PHP notice: Array to string conversion DELETE FROM `modx_register_messages` WHERE ( `modx_register_messages`.`topic` = :0 AND `modx_register_messages`.`id` = :1 ) Array ( [/:0\b/] => 1 [/:1\b/] => '996009f2374006606f4c0b0fda878af1' )