/**
  * Create a scheduled script that will store the modification made to an eZContentClass.
  *
  * @param eZContentClass Content class to be stored.
  * @param array[eZContentClassAttribute] Attributes of the new content class.
  * @param array Unordered view parameters
  */
 public function store(eZContentClass $class, array $attributes, array &$unorderedParameters)
 {
     $script = eZScheduledScript::create('syncobjectattributes.php', eZINI::instance('ezscriptmonitor.ini')->variable('GeneralSettings', 'PhpCliCommand') . ' extension/ezscriptmonitor/bin/' . eZScheduledScript::SCRIPT_NAME_STRING . ' -s ' . eZScheduledScript::SITE_ACCESS_STRING . ' --classid=' . $class->attribute('id'));
     $script->store();
     $unorderedParameters['ScheduledScriptID'] = $script->attribute('id');
     $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_MODIFIED);
 }
Example #2
0
<?php

/**
 * File containing list view
 *
 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
 * @license http://ez.no/licenses/gnu_gpl GNU GPLv2
 *
 */
$Module = $Params['Module'];
$scripts = eZScheduledScript::fetchCurrentScripts();
$tpl = eZTemplate::factory();
$tpl->setVariable('module', $Module);
$tpl->setVariable('scripts', $scripts);
$Result = array();
$Result['content'] = $tpl->fetch('design:scriptmonitor/list.tpl');
$Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('ezscriptmonitor', 'Script monitor')));
 /**
  * Publishes $toType to $newStatus.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Type $toType
  * @param int $newStatus
  */
 public function publishNewType(Type $toType, $newStatus)
 {
     $this->contentTypeGateway->publishTypeAndFields($toType->id, $toType->status, Type::STATUS_MODIFIED);
     $script = \eZScheduledScript::create('syncobjectattributes.php', \eZINI::instance('ezscriptmonitor.ini')->variable('GeneralSettings', 'PhpCliCommand') . ' extension/ezscriptmonitor/bin/' . \eZScheduledScript::SCRIPT_NAME_STRING . ' -s ' . \eZScheduledScript::SITE_ACCESS_STRING . ' --classid=' . $toType->id);
     $script->store();
 }
Example #4
0
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 *
 */
// Fetch all scripts that have not been started yet, and start them
$notStartedScripts = eZScheduledScript::fetchNotStartedScripts();
foreach ($notStartedScripts as $notStartedScript) {
    if (!$isQuiet) {
        $cli->output('Starting scheduled script in the background: ' . $notStartedScript->attribute('command'));
    }
    // Set progress to zero here. Do not trust that the script will do it. If it fails to do so, it will be executed over and over again forever.
    $notStartedScript->setAttribute('progress', 0);
    $notStartedScript->store();
    // Start the script in the background (will not wait for it to complete)
    execInBackground($notStartedScript->attribute('command') . ' --scriptid=' . $notStartedScript->attribute('id'));
}
// Fetch all old and completed scripts, and remove them
$scriptsToPurge = eZScheduledScript::fetchScriptsToPurge();
foreach ($scriptsToPurge as $oldScript) {
    $oldScript->remove();
}
// Execute a process in the background, should work on both Linux and Windows
// From php doc:
// http://no.php.net/manual/en/function.exec.php#86329
function execInBackground($command)
{
    if (substr(php_uname(), 0, 7) == 'Windows') {
        pclose(popen('start /B ' . $command, 'r'));
    } else {
        exec($command . ' > /dev/null &');
    }
}
Example #5
0
 static function fetchNotStartedScripts($asObject = true, $offset = false, $limit = false)
 {
     $conditions = array('progress' => array('<', 0));
     $limitation = null;
     if ($offset !== false or $limit !== false) {
         $limitation = array('offset' => $offset, 'length' => $limit);
     }
     return eZPersistentObject::fetchObjectList(eZScheduledScript::definition(), null, $conditions, null, $limitation, $asObject);
 }
Example #6
0
        $params['database'] = $dbName;
    }
    $db = eZDB::instance($dbImpl, $params, true);
    eZDB::setInstance($db);
}
$db->setIsSQLOutputEnabled((bool) $options['sql']);
// Log in admin user
$user = eZUser::fetchByName(isset($options['admin-user']) ? $options['admin-user'] : '******');
if ($user) {
    eZUser::setCurrentlyLoggedInUser($user, $user->attribute('id'));
} else {
    $cli->error('Could not fetch admin user object');
    $script->shutdown(1);
    return;
}
// Take care of script monitoring
$scheduledScript = false;
if (isset($options['scriptid'])) {
    $scheduledScript = eZScheduledScript::fetch($options['scriptid']);
}
// Do the update
if (isset($options['classid'])) {
    updateClass($options['classid'], $scheduledScript);
} else {
    $cli->notice('The classid parameter was not given, will check all classes.');
    foreach (eZContentClass::fetchList(eZContentClass::VERSION_STATUS_MODIFIED, false) as $class) {
        $cli->output('Checking class with ID: ' . $class['id']);
        updateClass($class['id'], $scheduledScript);
    }
}
$script->shutdown();
Example #7
0
<?php

/**
 * File containing view controller
 *
 * @copyright Copyright (C) eZ Systems AS.
 * @license For full copyright and license information view LICENSE file distributed with this source code.
 *
 */
$Module = $Params['Module'];
$scriptID = $Params['ScriptID'];
$script = eZScheduledScript::fetch($scriptID);
if (is_object($script)) {
    $scriptName = $script->attribute('name');
} else {
    $scriptName = ezpI18n::tr('ezscriptmonitor', 'Script not found');
}
$tpl = eZTemplate::factory();
$tpl->setVariable('module', $Module);
$tpl->setVariable('script', $script);
$Result = array();
$Result['content'] = $tpl->fetch('design:scriptmonitor/view.tpl');
$Result['path'] = array(array('url' => '/scriptmonitor/list/', 'text' => ezpI18n::tr('ezscriptmonitor', 'Script monitor')), array('url' => false, 'text' => $scriptName));