/**
  * Upgrade the AppCacheView table to the latest system version.
  *
  * This recreates the table and populates with data.
  *
  * @param bool $checkOnly only check if the upgrade is needed if true
  * @param string $lang not currently used
  */
 public function upgradeCacheView($fill = true)
 {
     $this->initPropel(true);
     $lang = "en";
     require_once 'classes/model/AppCacheView.php';
     //check the language, if no info in config about language, the default is 'en'
     G::loadClass('configuration');
     $oConf = new Configurations();
     $oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', '');
     $appCacheViewEngine = $oConf->aConfig;
     //setup the appcacheview object, and the path for the sql files
     $appCache = new AppCacheView();
     $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
     $userGrants = $appCache->checkGrantsForUser(false);
     $currentUser = $userGrants['user'];
     $currentUserIsSuper = $userGrants['super'];
     //if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user.
     if (!$currentUserIsSuper) {
         $appCache->checkGrantsForUser(true);
         $appCache->setSuperForUser($currentUser);
         $currentUserIsSuper = true;
     }
     CLI::logging("-> Creating table\n");
     //now check if table APPCACHEVIEW exists, and it have correct number of fields, etc.
     $res = $appCache->checkAppCacheView();
     CLI::logging("-> Creating triggers\n");
     //now check if we have the triggers installed
     $triggers = array();
     $triggers[] = $appCache->triggerAppDelegationInsert($lang, $checkOnly);
     $triggers[] = $appCache->triggerAppDelegationUpdate($lang, $checkOnly);
     $triggers[] = $appCache->triggerApplicationUpdate($lang, $checkOnly);
     $triggers[] = $appCache->triggerApplicationDelete($lang, $checkOnly);
     $triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly);
     if ($fill) {
         CLI::logging("-> Rebuild Cache View\n");
         //build using the method in AppCacheView Class
         $res = $appCache->fillAppCacheView($lang);
         //set status in config table
         $confParams = array('LANG' => $lang, 'STATUS' => 'active');
     }
     $oConf->aConfig = $confParams;
     $oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', '');
     // removing casesList configuration records. TODO: removing these lines that resets all the configurations records
     $oCriteria = new Criteria();
     $oCriteria->add(ConfigurationPeer::CFG_UID, "casesList");
     $oCriteria->add(ConfigurationPeer::OBJ_UID, array("todo", "draft", "sent", "unassigned", "paused", "cancelled"), Criteria::NOT_IN);
     ConfigurationPeer::doDelete($oCriteria);
     // end of reset
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      Connection $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete($con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(ConfigurationPeer::DATABASE_NAME);
     }
     try {
         $con->begin();
         ConfigurationPeer::doDelete($this, $con);
         $this->setDeleted(true);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }
Exemple #3
0
    /**

     * Upgrade the AppCacheView table to the latest system version.

     *

     * This recreates the table and populates with data.

     *

     * @param bool $checkOnly only check if the upgrade is needed if true

     * @param string $lang not currently used

     */

    public function upgradeCacheView($fill = true, $checkOnly = false, $lang = "en")

    {

        $this->initPropel(true);



        //require_once ('classes/model/AppCacheView.php');

        //check the language, if no info in config about language, the default is 'en'

        G::LoadClass("configuration");



        $oConf = new Configurations();

        $oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', '');

        $appCacheViewEngine = $oConf->aConfig;



        //setup the appcacheview object, and the path for the sql files

        $appCache = new AppCacheView();

        $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);



        $userGrants = $appCache->checkGrantsForUser(false);



        $currentUser = $userGrants['user'];

        $currentUserIsSuper = $userGrants['super'];

        //if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user.



        if (!$currentUserIsSuper) {

            $appCache->checkGrantsForUser(true);

            $appCache->setSuperForUser($currentUser);

            $currentUserIsSuper = true;

        }



        CLI::logging("-> Creating tables \n");

        //now check if table APPCACHEVIEW exists, and it have correct number of fields, etc.

        $res = $appCache->checkAppCacheView();



        CLI::logging("-> Update DEL_LAST_INDEX field in APP_DELEGATION table \n");

        //Update APP_DELEGATION.DEL_LAST_INDEX data

        $res = $appCache->updateAppDelegationDelLastIndex($lang, $checkOnly);



        CLI::logging("-> Verifying roles permissions in RBAC \n");

        //Update table RBAC permissions

        Bootstrap::LoadSystem( 'rbac' );

        $RBAC = & RBAC::getSingleton();

        $RBAC->initRBAC();

        $result = $RBAC->verifyPermissions();

        if (count($result) > 1) {

            foreach ($result as $item) {

                CLI::logging("    $item... \n");

            }

        } else {

            CLI::logging("    All roles permissions already updated \n");

        }



        CLI::logging("-> Creating triggers\n");

        //now check if we have the triggers installed

        $triggers = array();

        $triggers[] = $appCache->triggerAppDelegationInsert($lang, $checkOnly);

        $triggers[] = $appCache->triggerAppDelegationUpdate($lang, $checkOnly);

        $triggers[] = $appCache->triggerApplicationUpdate($lang, $checkOnly);

        $triggers[] = $appCache->triggerApplicationDelete($lang, $checkOnly);

        $triggers[] = $appCache->triggerSubApplicationInsert($lang, $checkOnly);

        $triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly);



        if ($fill) {

            CLI::logging("-> Rebuild Cache View with language $lang...\n");

            //build using the method in AppCacheView Class

            $res = $appCache->fillAppCacheView($lang);

        }

        //set status in config table

        $confParams = Array('LANG' => $lang, 'STATUS' => 'active');

        $oConf->aConfig = $confParams;

        $oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', '');



        // removing casesList configuration records. TODO: removing these lines that resets all the configurations records

        $oCriteria = new Criteria();

        $oCriteria->add(ConfigurationPeer::CFG_UID, "casesList");

        $oCriteria->add(ConfigurationPeer::OBJ_UID, array("todo", "draft", "sent", "unassigned", "paused", "cancelled"), Criteria::NOT_IN);

        ConfigurationPeer::doDelete($oCriteria);

        // end of reset



        //close connection

        if (substr(PHP_OS, 0, 3) != 'WIN') {

            $connection = Propel::getConnection( 'workflow' );



            $sql_sleep = "SELECT * FROM information_schema.processlist WHERE command = 'Sleep' and user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() ORDER BY id;";

            $stmt_sleep = $connection->createStatement();

            $rs_sleep = $stmt_sleep->executeQuery( $sql_sleep, ResultSet::FETCHMODE_ASSOC );



            while ($rs_sleep->next()) {

                $row_sleep = $rs_sleep->getRow();

                $oStatement_sleep = $connection->prepareStatement( "kill ". $row_sleep['ID'] );

                $oStatement_sleep->executeQuery();

            }



            $sql_query = "SELECT * FROM information_schema.processlist WHERE user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() and time > 0 ORDER BY id;";

            $stmt_query = $connection->createStatement();

            $rs_query = $stmt_query->executeQuery( $sql_query, ResultSet::FETCHMODE_ASSOC );



            while ($rs_query->next()) {

                $row_query = $rs_query->getRow();

                $oStatement_query = $connection->prepareStatement( "kill ". $row_query['ID'] );

                $oStatement_query->executeQuery();

            }

        }

    }
function executeUpdateAppTitle()
{
    try {
        global $sFilter;
        if ($sFilter != "" && strpos($sFilter, "update-case-labels") === false) {
            return false;
        }
        $criteriaConf = new Criteria("workflow");
        $criteriaConf->addSelectColumn(ConfigurationPeer::OBJ_UID);
        $criteriaConf->addSelectColumn(ConfigurationPeer::CFG_VALUE);
        $criteriaConf->add(ConfigurationPeer::CFG_UID, "TAS_APP_TITLE_UPDATE");
        $rsCriteriaConf = ConfigurationPeer::doSelectRS($criteriaConf);
        $rsCriteriaConf->setFetchmode(ResultSet::FETCHMODE_ASSOC);
        setExecutionMessage("Update case labels");
        saveLog("updateCaseLabels", "action", "Update case labels", "c");
        while ($rsCriteriaConf->next()) {
            $row = $rsCriteriaConf->getRow();
            $taskUid = $row["OBJ_UID"];
            $lang = $row["CFG_VALUE"];
            //Update case labels
            $appcv = new AppCacheView();
            $appcv->appTitleByTaskCaseLabelUpdate($taskUid, $lang, 1);
            //Delete record
            $criteria = new Criteria("workflow");
            $criteria->add(ConfigurationPeer::CFG_UID, "TAS_APP_TITLE_UPDATE");
            $criteria->add(ConfigurationPeer::OBJ_UID, $taskUid);
            $criteria->add(ConfigurationPeer::CFG_VALUE, $lang);
            $numRowDeleted = ConfigurationPeer::doDelete($criteria);
            saveLog("updateCaseLabels", "action", "OK Task {$taskUid}");
        }
        setExecutionResultMessage("DONE");
    } catch (Exception $e) {
        setExecutionResultMessage("WITH ERRORS", "error");
        eprintln("  '-" . $e->getMessage(), "red");
        saveLog("updateCaseLabels", "error", "Error updating case labels: " . $e->getMessage());
    }
}
Exemple #5
0
 public function update($fields)
 {
     require_once "classes/model/AppCacheView.php";
     require_once "classes/model/Configuration.php";
     $con = Propel::getConnection(TaskPeer::DATABASE_NAME);
     try {
         $con->begin();
         $this->load($fields["TAS_UID"]);
         $this->fromArray($fields, BasePeer::TYPE_FIELDNAME);
         if ($this->validate()) {
             $taskDefTitlePrevious = null;
             $criteria = new Criteria("workflow");
             $criteria->addSelectColumn(ContentPeer::CON_VALUE);
             $criteria->add(ContentPeer::CON_CATEGORY, "TAS_DEF_TITLE");
             $criteria->add(ContentPeer::CON_ID, $fields["TAS_UID"]);
             $criteria->add(ContentPeer::CON_LANG, SYS_LANG);
             $rsCriteria = ContentPeer::doSelectRS($criteria);
             $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
             while ($rsCriteria->next()) {
                 $row = $rsCriteria->getRow();
                 $taskDefTitlePrevious = $row["CON_VALUE"];
             }
             $contentResult = 0;
             if (array_key_exists("TAS_TITLE", $fields)) {
                 $contentResult += $this->setTasTitle($fields["TAS_TITLE"]);
             }
             if (array_key_exists("TAS_DESCRIPTION", $fields)) {
                 $contentResult += $this->setTasDescription($fields["TAS_DESCRIPTION"]);
             }
             if (array_key_exists("TAS_DEF_TITLE", $fields)) {
                 $contentResult += $this->setTasDefTitle($fields["TAS_DEF_TITLE"]);
             }
             if (array_key_exists("TAS_DEF_DESCRIPTION", $fields)) {
                 $contentResult += $this->setTasDefDescription($fields["TAS_DEF_DESCRIPTION"]);
             }
             if (array_key_exists("TAS_DEF_PROC_CODE", $fields)) {
                 $contentResult += $this->setTasDefProcCode($fields["TAS_DEF_PROC_CODE"]);
             }
             if (array_key_exists("TAS_DEF_MESSAGE", $fields)) {
                 $contentResult += $this->setTasDefMessage(trim($fields["TAS_DEF_MESSAGE"]));
             }
             if (array_key_exists("TAS_DEF_SUBJECT_MESSAGE", $fields)) {
                 $contentResult += $this->setTasDefSubjectMessage(trim($fields["TAS_DEF_SUBJECT_MESSAGE"]));
             }
             if (array_key_exists("TAS_CALENDAR", $fields)) {
                 $contentResult += $this->setTasCalendar($fields['TAS_UID'], $fields["TAS_CALENDAR"]);
             }
             $result = $this->save();
             $result = $result == 0 ? $contentResult > 0 ? 1 : 0 : $result;
             $con->commit();
             if ($result == 1 && array_key_exists("TAS_DEF_TITLE", $fields) && $fields["TAS_DEF_TITLE"] != $taskDefTitlePrevious) {
                 $criteria = new Criteria("workflow");
                 $criteria->addAsColumn("APPCV_NUM_ROWS", "COUNT(DISTINCT " . AppCacheViewPeer::APP_UID . ")");
                 $criteria->add(AppCacheViewPeer::DEL_THREAD_STATUS, "OPEN");
                 $criteria->add(AppCacheViewPeer::TAS_UID, $fields["TAS_UID"]);
                 $rsCriteria = AppCacheViewPeer::doSelectRS($criteria);
                 $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
                 $rsCriteria->next();
                 $row = $rsCriteria->getRow();
                 $appcvNumRows = intval($row["APPCV_NUM_ROWS"]);
                 if ($appcvNumRows <= 1000) {
                     $appcv = new AppCacheView();
                     $appcv->appTitleByTaskCaseLabelUpdate($fields["TAS_UID"], SYS_LANG);
                     $result = 2;
                 } else {
                     //Delete record
                     $criteria = new Criteria("workflow");
                     $criteria->add(ConfigurationPeer::CFG_UID, "TAS_APP_TITLE_UPDATE");
                     $criteria->add(ConfigurationPeer::OBJ_UID, $fields["TAS_UID"]);
                     $criteria->add(ConfigurationPeer::CFG_VALUE, SYS_LANG);
                     $numRowDeleted = ConfigurationPeer::doDelete($criteria);
                     //Insert record
                     $conf = new Configuration();
                     $conf->create(array("CFG_UID" => "TAS_APP_TITLE_UPDATE", "OBJ_UID" => $fields["TAS_UID"], "CFG_VALUE" => SYS_LANG, "PRO_UID" => "", "USR_UID" => "", "APP_UID" => ""));
                     $result = 3;
                 }
             }
             return $result;
         } else {
             $con->rollback();
             throw new Exception("Failed Validation in class " . get_class($this) . ".");
         }
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
 /**
  * Upgrade the AppCacheView table to the latest system version.
  *
  * This recreates the table and populates with data.
  *
  * @param bool $checkOnly only check if the upgrade is needed if true
  * @param string $lang not currently used
  */
 public function upgradeCacheView($fill = true, $checkOnly = false, $lang = "en")
 {
     $this->initPropel(true);
     //require_once ('classes/model/AppCacheView.php');
     //check the language, if no info in config about language, the default is 'en'
     G::LoadClass("configuration");
     $oConf = new Configurations();
     $oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', '');
     $appCacheViewEngine = $oConf->aConfig;
     //setup the appcacheview object, and the path for the sql files
     $appCache = new AppCacheView();
     $appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
     $userGrants = $appCache->checkGrantsForUser(false);
     $currentUser = $userGrants['user'];
     $currentUserIsSuper = $userGrants['super'];
     //if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user.
     if (!$currentUserIsSuper) {
         $appCache->checkGrantsForUser(true);
         $appCache->setSuperForUser($currentUser);
         $currentUserIsSuper = true;
     }
     CLI::logging("-> Creating table\n");
     //now check if table APPCACHEVIEW exists, and it have correct number of fields, etc.
     $res = $appCache->checkAppCacheView();
     CLI::logging("-> Update DEL_LAST_INDEX field in APP_DELEGATION table\n");
     //Update APP_DELEGATION.DEL_LAST_INDEX data
     $res = $appCache->updateAppDelegationDelLastIndex($lang, $checkOnly);
     CLI::logging("-> Verifying roles permissions in RBAC \n");
     //Update table RBAC permissions
     Bootstrap::LoadSystem('rbac');
     $RBAC =& RBAC::getSingleton();
     $RBAC->initRBAC();
     $result = $RBAC->verifyPermissions();
     if (count($result) > 1) {
         foreach ($result as $item) {
             CLI::logging("    {$item}... \n");
         }
     } else {
         CLI::logging("    All roles permissions already updated \n");
     }
     CLI::logging("-> Creating triggers\n");
     //now check if we have the triggers installed
     $triggers = array();
     $triggers[] = $appCache->triggerAppDelegationInsert($lang, $checkOnly);
     $triggers[] = $appCache->triggerAppDelegationUpdate($lang, $checkOnly);
     $triggers[] = $appCache->triggerApplicationUpdate($lang, $checkOnly);
     $triggers[] = $appCache->triggerApplicationDelete($lang, $checkOnly);
     $triggers[] = $appCache->triggerSubApplicationInsert($lang, $checkOnly);
     $triggers[] = $appCache->triggerContentUpdate($lang, $checkOnly);
     if ($fill) {
         CLI::logging("-> Rebuild Cache View with language {$lang}...\n");
         //build using the method in AppCacheView Class
         $res = $appCache->fillAppCacheView($lang);
         //set status in config table
         $confParams = array('LANG' => $lang, 'STATUS' => 'active');
     }
     $oConf->aConfig = $confParams;
     $oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', '');
     // removing casesList configuration records. TODO: removing these lines that resets all the configurations records
     $oCriteria = new Criteria();
     $oCriteria->add(ConfigurationPeer::CFG_UID, "casesList");
     $oCriteria->add(ConfigurationPeer::OBJ_UID, array("todo", "draft", "sent", "unassigned", "paused", "cancelled"), Criteria::NOT_IN);
     ConfigurationPeer::doDelete($oCriteria);
     // end of reset
 }
 /**
  * Delete a task
  *
  * @param string $sTaskUID
  * @return void
  */
 public function deleteTask($sTaskUID = '')
 {
     try {
         //Instance classes
         $oTask = new Task();
         $oTasks = new Tasks();
         $oTaskUser = new TaskUser();
         $oStep = new Step();
         $oStepTrigger = new StepTrigger();
         //Get task information
         $aFields = $oTask->load($sTaskUID);
         //Delete routes
         $oTasks->deleteAllRoutesOfTask($aFields['PRO_UID'], $sTaskUID, true);
         //Delete gateways
         $oTasks->deleteAllGatewayOfTask($aFields['PRO_UID'], $sTaskUID, true);
         //Delete the users assigned to task
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(TaskUserPeer::TAS_UID, $sTaskUID);
         $oDataset1 = TaskUserPeer::doSelectRS($oCriteria);
         $oDataset1->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset1->next();
         while ($aRow1 = $oDataset1->getRow()) {
             $oTaskUser->remove($aRow1['TAS_UID'], $aRow1['USR_UID'], $aRow1['TU_TYPE'], $aRow1['TU_RELATION']);
             $oDataset1->next();
         }
         //Delete the steps of task
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(StepPeer::TAS_UID, $sTaskUID);
         $oDataset1 = StepPeer::doSelectRS($oCriteria);
         $oDataset1->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset1->next();
         while ($aRow1 = $oDataset1->getRow()) {
             //Delete the triggers assigned to step
             /* $oCriteria = new Criteria('workflow');
                $oCriteria->add(StepTriggerPeer::STEP_UID, $aRow1['STEP_UID']);
                $oDataset2 = StepTriggerPeer::doSelectRS($oCriteria);
                $oDataset2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
                $oDataset2->next();
                while ($aRow2 = $oDataset2->getRow()) {
                $oStepTrigger->remove($aRow2['STEP_UID'], $aRow2['TAS_UID'], $aRow2['TRI_UID'], $aRow2['ST_TYPE']);
                $oDataset2->next();
                } */
             $oStep->remove($aRow1['STEP_UID']);
             $oDataset1->next();
         }
         //Delete step triggers
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(StepTriggerPeer::TAS_UID, $sTaskUID);
         StepTriggerPeer::doDelete($oCriteria);
         //Delete permissions
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(ObjectPermissionPeer::TAS_UID, $sTaskUID);
         ObjectPermissionPeer::doDelete($oCriteria);
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(ObjectPermissionPeer::OP_TASK_SOURCE, $sTaskUID);
         ObjectPermissionPeer::doDelete($oCriteria);
         //Delete Cases Schedulers
         $criteria = new Criteria("workflow");
         $criteria->add(CaseSchedulerPeer::TAS_UID, $sTaskUID, Criteria::EQUAL);
         $result = CaseSchedulerPeer::doDelete($criteria);
         //Delete Configuration
         $criteria = new Criteria("workflow");
         $criteria->add(ConfigurationPeer::OBJ_UID, $sTaskUID, Criteria::EQUAL);
         $result = ConfigurationPeer::doDelete($criteria);
         //Delete task
         $oTask->remove($sTaskUID);
     } catch (Exception $oError) {
         throw $oError;
     }
 }