Esempio n. 1
0
 public static function run($allRules = false)
 {
     $database = Database::singleton();
     Notifications::addLog('------------------------- EXEC ENGINE STARTED -------------------------', 'ExecEngine');
     // Load the execEngine functions (security hazard :P)
     $files = getDirectoryList(__DIR__ . '/functions');
     foreach ($files as $file) {
         if (substr($file, -3) !== 'php') {
             continue;
         }
         require_once __DIR__ . '/functions/' . $file;
         Notifications::addLog('Included file: ' . __DIR__ . '/functions/' . $file, 'ExecEngine');
     }
     self::$roleName = Config::get('execEngineRoleName', 'execEngine');
     $role = Role::getRoleByName(self::$roleName);
     $maxRunCount = Config::get('maxRunCount', 'execEngine');
     self::$runCount = 0;
     self::$autoRerun = Config::get('autoRerun', 'execEngine');
     if ($role) {
         // Get all rules that are maintained by the ExecEngine
         while (self::$doRun) {
             self::$doRun = false;
             self::$runCount++;
             if (self::$runCount > $maxRunCount) {
                 throw new Exception('Maximum reruns exceeded for ExecEngine (rules with violations:' . implode(', ', $rulesThatHaveViolations) . ')', 500);
             }
             Notifications::addLog("ExecEngine run #" . self::$runCount . " (auto rerun: " . var_export(self::$autoRerun, true) . ") for role '" . $role->label . "'", 'ExecEngine');
             // Determine affected rules that must be checked by the exec engine
             $affectedConjuncts = (array) RuleEngine::getAffectedInvConjuncts($database->getAffectedConcepts(), $database->getAffectedRelations());
             $affectedConjuncts = array_merge($affectedConjuncts, (array) RuleEngine::getAffectedSigConjuncts($database->getAffectedConcepts(), $database->getAffectedRelations()));
             $affectedRules = array();
             foreach ($affectedConjuncts as $conjunctId) {
                 $conjunct = RuleEngine::getConjunct($conjunctId);
                 foreach ($conjunct['invariantRuleNames'] as $ruleName) {
                     $affectedRules[] = $ruleName;
                 }
                 foreach ($conjunct['signalRuleNames'] as $ruleName) {
                     $affectedRules[] = $ruleName;
                 }
             }
             // Check rules
             $rulesThatHaveViolations = array();
             foreach ($role->maintains() as $ruleName) {
                 if (!in_array($ruleName, $affectedRules) && !$allRules) {
                     continue;
                 }
                 // skip this rule
                 $rule = RuleEngine::getRule($ruleName);
                 $violations = RuleEngine::checkRule($rule, false);
                 if (count($violations)) {
                     $rulesThatHaveViolations[] = $rule['name'];
                     // Fix violations for every rule
                     ExecEngine::fixViolations($rule, $violations);
                     // Conjunct violations are not cached, because they are fixed by the ExecEngine
                     // If $autoRerun, set $doRun to true because violations have been fixed (this may fire other execEngine rules)
                     if (self::$autoRerun) {
                         self::$doRun = true;
                     }
                 }
             }
         }
     } else {
         Notifications::addInfo("ExecEngine extension included but role '" . self::$roleName . "' not found.");
     }
     Notifications::addLog('------------------------- END OF EXEC ENGINE -------------------------', 'ExecEngine');
 }
Esempio n. 2
0
 /**
  * Add roles to user to make them a concierge
  */
 public function addRole($name)
 {
     $role_id = Role::getRoleByName($name);
     $this->roles()->attach($role_id);
 }
Esempio n. 3
0
 public function createUserImport($form, $sendEmail = true)
 {
     $values = $form->getValues();
     $pass = Base_PasswordGenerator::generate();
     $values['password'] = $pass['hashed'];
     if ($values['symbol'] != '') {
         /**
          * 1. odnalezenia brancha o podanym symbolu (pole "symbol") w polu profil w danych z csv.
          * 2. dopisanie do profile "id_branch", "id_user", "landing" zawsze na /contact
          * 3. dopisanie uprawnien dla usera do grupy uprawnien "logowanie"
          * 4. dopisanie uprawnien dla usera do konkretnej roli szukanej po nazwie podanej w danych z csv z userami w polu "rola".
          */
         $branchModel = new Branch();
         $branch = $branchModel->getBranchBySymbol($values['symbol']);
         if (isset($branch['id'])) {
             $valuesProfile['id_branch'] = $branch['id'];
             $valuesProfile['landing'] = '/contact';
         }
         if ($values['rola'] != '') {
             $roleModel = new Role();
             $rola = $roleModel->getRoleByName($values['rola']);
             if (isset($rola['id'])) {
                 $valuesRole['id_role'] = $rola['id'];
                 $valuesRole['id_profile'] = '';
                 // po dodaniu profilu wstawiamy jego id.
             }
         }
     }
     if (isset($values['symbol'])) {
         unset($values['symbol']);
     }
     if (isset($values['rola'])) {
         unset($values['rola']);
     }
     $user = new User();
     $row = $user->createRow($values);
     $id_user = $row->save();
     if (is_array($valuesProfile)) {
         $valuesProfile['id_user'] = $id_user;
         $profile = new Profile();
         $rowProfile = $profile->createRow($valuesProfile);
         $id_profile = $rowProfile->save();
         if (isset($id_profile) && isset($valuesRole['id_role'])) {
             $valuesRole['id_profile'] = $id_profile;
             $role = new ProfileRole();
             $rowRole = $role->createRow($valuesRole);
             $id_role = $rowRole->save();
             $valuesProfileGroup['id_profile'] = $id_profile;
             $valuesProfileGroup['id_group'] = 5;
             $profileGroup = new ProfileGroup();
             $rowProfileGroup = $profileGroup->createRow($valuesProfileGroup);
             $id_profile_group = $rowProfileGroup->save();
         }
     }
     $passwordData['id_user'] = $id_user;
     $passwordData['password'] = $pass['hashed'];
     $userPassword = new UserPassword();
     $rowPassword = $userPassword->createRow($passwordData);
     $rowPassword->save();
     /*
      if($sendEmail == true) {
      $mailer = new Logic_Mailer(Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'), $translate);
      $user_row = $user->findOne($id_user);
      $mailer->userPass($pass['clean'], $user_row);
      }
     */
 }