Example #1
0
 public static function callHooks($hookpoint, $hookpointParams)
 {
     Logger::getLogger('HOOKS')->debug("Hook '{$hookpoint}' called");
     foreach (Hooks::getHooks($hookpoint) as $hook) {
         // Determine funtioncall
         if ($hook['class']) {
             $callback = $hook['class'] . '::' . $hook['function'];
         } else {
             $callback = $hook['function'];
         }
         // Construct params
         $callBackParams = array();
         foreach ((array) $hook['params'] as $param) {
             if (substr((string) $param, 0, 1) == '$') {
                 $callBackParams[] = $hookpointParams[substr($param, 1)];
             } else {
                 $callBackParams[] = $param;
             }
         }
         $log = $callback . '(' . implode(', ', $callBackParams) . ')';
         Logger::getLogger('HOOKS')->debug("Call hook {$log}");
         call_user_func_array($callback, $callBackParams);
     }
 }
Example #2
0
<?php

namespace Ampersand\Extension\Messaging;

use Exception;
use Ampersand\Hooks;
use Ampersand\Config;
use Ampersand\Log\Logger;
use Pushalot;
require_once __DIR__ . '/lib/pushalot_api.php';
// Define hooks
$hook = array('class' => '\\Ampersand\\Extension\\Messaging\\PushalotNotifications', 'function' => 'pushNotificationCache', 'filename' => 'Pushalot.php', 'filepath' => 'extensions/Messaging', 'params' => array());
Hooks::addHook('postDatabaseCommitTransaction', $hook);
$hook = array('class' => '\\Ampersand\\Extension\\Messaging\\PushalotNotifications', 'function' => 'clearNotificationCache', 'filename' => 'Pushalot.php', 'filepath' => 'extensions/Messaging', 'params' => array());
Hooks::addHook('postDatabaseRollbackTransaction', $hook);
class PushalotNotifications
{
    private static $notifications = array();
    public static function execEnginePushNotificationOnCommit($userKeys, $message, $title = null, $url = null, $urltitle = null)
    {
        Logger::getLogger('MESSAGING')->debug('Pushalot[execEnginePushNotificationOnCommit' . ']; $userKeys=[' . $userKeys . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']');
        if ($userKeys == '_NULL') {
            $userKeys = array(null);
        } else {
            $userKeys = explode('_AND', $userKeys);
        }
        self::pushNotificationOnCommit($userKeys, $message, $title, $url, $urltitle);
    }
    public static function pushNotificationOnCommit($userKeys, $message, $title = null, $url = null, $urltitle = null)
    {
        Logger::getLogger('MESSAGING')->debug('Pushalot[pushNotificationOnCommit' . ']; $userKeys=[' . $userKeys . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']');
Example #3
0
use Exception;
use Ampersand\Hooks;
use Ampersand\Database\Database;
use Ampersand\AngularApp;
use Ampersand\Config;
use Ampersand\Role;
use Ampersand\Log\Logger;
use Ampersand\Rule\Rule;
use Ampersand\Rule\RuleEngine;
use Ampersand\Rule\Violation;
use function Ampersand\Helper\getDirectoryList;
// Define hooks
$hook1 = array('class' => '\\Ampersand\\Extension\\ExecEngine\\ExecEngine', 'function' => 'run', 'filename' => 'ExecEngine.php', 'filepath' => 'extensions/ExecEngine', 'params' => array());
Hooks::addHook('preDatabaseCloseTransaction', $hook1);
$hook2 = array('class' => '\\Ampersand\\Extension\\ExecEngine\\ExecEngine', 'function' => 'run', 'filename' => 'ExecEngine.php', 'filepath' => 'extensions/ExecEngine', 'params' => array(true));
Hooks::addHook('postDatabaseReinstallDB', $hook2);
// UI
AngularApp::addMenuItem('ext', 'extensions/ExecEngine/ui/views/MenuItem.html', function ($session) {
    $roles = Config::get('allowedRolesForRunFunction', 'execEngine');
    return !empty(array_intersect($session->getActiveRoles(), (array) $roles)) || is_null($roles);
});
AngularApp::addJS('extensions/ExecEngine/ui/js/ExecEngine.js');
// API
$GLOBALS['api']['files'][] = __DIR__ . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'run.php';
// Config (can be overwritten in localSettings.php)
Config::set('execEngineRoleName', 'execEngine', 'ExecEngine');
Config::set('autoRerun', 'execEngine', true);
Config::set('maxRunCount', 'execEngine', 10);
class ExecEngine
{
    private static $roleName;
Example #4
0
 /**
  * Function to request closing the open database transaction
  * @param string $succesMessage specifies success/info message when invariants hold
  * @param boolean $databaseCommit specifies to commit (true) or rollback (false) when all invariants hold
  * @param Atom $atomStoreNewContent specifies to store the new content for the updated/created atom
  * @return boolean specifies if invariant rules hold (true) or not (false)
  */
 public function closeTransaction($succesMessage = 'Updated', $databaseCommit = null, &$atomStoreNewContent = null)
 {
     Hooks::callHooks('preDatabaseCloseTransaction', get_defined_vars());
     $this->logger->info("Closing database transaction");
     $this->logger->info("Checking all affected conjuncts");
     // Check invariant rules (we only have to check the affected invariant rules)
     $affectedConjuncts = RuleEngine::getAffectedConjuncts($this->affectedConcepts, $this->affectedRelations, 'inv');
     // Get affected invariant conjuncts
     $invariantRulesHold = RuleEngine::checkInvariantRules($affectedConjuncts, true);
     // Check all process rules that are relevant for the activate roles
     RuleEngine::checkProcessRules();
     unset($this->affectedConcepts, $this->affectedRelations);
     $this->affectedConcepts = array();
     $this->affectedRelations = array();
     if (!is_null($atomStoreNewContent)) {
         $atomStoreNewContent->setStoredContent();
     }
     // Determine if transaction should be committed or not when all invariant rules hold based on $requestType
     if (is_null($databaseCommit)) {
         $databaseCommit = $this->processRequestType();
     }
     if ($invariantRulesHold && $databaseCommit) {
         $this->commitTransaction();
         // commit database transaction
         Logger::getUserLogger()->notice($succesMessage);
     } elseif (Config::get('ignoreInvariantViolations', 'transactions') && $databaseCommit) {
         $this->commitTransaction();
         Logger::getUserLogger()->warning("Transaction committed with invariant violations");
     } elseif ($invariantRulesHold) {
         $this->logger->info("Invariant rules hold, but no database commit requested");
         $this->rollbackTransaction();
         // rollback database transaction
     } else {
         $this->logger->info("Invariant rules do not hold");
         $this->rollbackTransaction();
         // rollback database transaction
     }
     Hooks::callHooks('postDatabaseCloseTransaction', get_defined_vars());
     return $this->invariantRulesHold = $invariantRulesHold;
 }