Ejemplo n.º 1
0
    /**

     * Migrate all cases to New list

     *

     * return all LIST TABLES with data

     */

    public function migrateList ($workSpace)

    {

        if ($this->listFirstExecution('check')) {

            return 1;

        }

        $this->initPropel(true);

        $appCache = new AppCacheView();

        $users    = new Users();

        G::LoadClass("case");

        $case = new Cases();



        //Select data CANCELLED

        $canCriteria = $appCache->getSelAllColumns();

        $canCriteria->add(AppCacheViewPeer::APP_STATUS, "CANCELLED", CRITERIA::EQUAL);

        $canCriteria->add(AppCacheViewPeer::DEL_LAST_INDEX, "1", CRITERIA::EQUAL);

        $rsCriteria = AppCacheViewPeer::doSelectRS($canCriteria);

        $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        //Insert data LIST_CANCELED

        while ($rsCriteria->next()) {

              $row = $rsCriteria->getRow();

              $listCanceled = new ListCanceled();

              $listCanceled->remove($row["APP_UID"]);

              $listCanceled->setDeleted(false);

              $listCanceled->create($row);

        }

        CLI::logging("> Completed table LIST_CANCELED\n");



        //Select data COMPLETED

        $comCriteria = $appCache->getSelAllColumns();

        $comCriteria->add(AppCacheViewPeer::APP_STATUS, "COMPLETED", CRITERIA::EQUAL);

        $comCriteria->add(AppCacheViewPeer::DEL_LAST_INDEX, "1", CRITERIA::EQUAL);

        $rsCriteria = AppCacheViewPeer::doSelectRS($comCriteria);

        $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        //Insert new data LIST_COMPLETED

        while ($rsCriteria->next()) {

              $row = $rsCriteria->getRow();

              $listCompleted = new ListCompleted();

              $listCompleted->remove($row["APP_UID"]);

              $listCompleted->setDeleted(false);

              $listCompleted->create($row);

        }

        CLI::logging("> Completed table LIST_COMPLETED\n");



        //Select data TO_DO OR DRAFT

        $inbCriteria = $appCache->getSelAllColumns();

        $rsCriteria = AppCacheViewPeer::doSelectRS($inbCriteria);

        $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);



        $criteriaUser = new Criteria();

        $criteriaUser->addSelectColumn( UsersPeer::USR_UID );

        $criteriaUser->addSelectColumn( UsersPeer::USR_FIRSTNAME );

        $criteriaUser->addSelectColumn( UsersPeer::USR_LASTNAME );

        $criteriaUser->addSelectColumn( UsersPeer::USR_USERNAME );

        //Insert new data LIST_INBOX

        while ($rsCriteria->next()) {

            $row = $rsCriteria->getRow();

            $isSelfService = ($row['USR_UID'] == '') ? true : false;

            if($row["DEL_THREAD_STATUS"] == 'OPEN'){

                //Update information about the previous_user

                $row["DEL_PREVIOUS_USR_UID"] = $row["PREVIOUS_USR_UID"];

                $criteriaUser->add( UsersPeer::USR_UID, $row["PREVIOUS_USR_UID"] );

                $datasetU = UsersPeer::doSelectRS($criteriaUser);

                $datasetU->setFetchmode(ResultSet::FETCHMODE_ASSOC);

                $datasetU->next();

                $arrayUsers = $datasetU->getRow();

                $row["DEL_PREVIOUS_USR_USERNAME"] = $arrayUsers["USR_USERNAME"];

                $row["DEL_PREVIOUS_USR_FIRSTNAME"]= $arrayUsers["USR_FIRSTNAME"];

                $row["DEL_PREVIOUS_USR_LASTNAME"] = $arrayUsers["USR_LASTNAME"];

                //Update the due date

                $row["DEL_DUE_DATE"]         = $row["DEL_TASK_DUE_DATE"];

                $listInbox = new ListInbox();

                $listInbox->remove($row["APP_UID"],$row["DEL_INDEX"]);

                $listInbox->setDeleted(false);

                $listInbox->create($row, $isSelfService);

            } else {

                // create participated List when the thread is CLOSED

                $listParticipatedHistory = new ListParticipatedHistory();

                $listParticipatedHistory->remove($row['APP_UID'], $row['DEL_INDEX']);

                $listParticipatedHistory = new ListParticipatedHistory();

                $listParticipatedHistory->create($row);



                $oCriteria = new Criteria('workflow');

                $oCriteria->add(ListParticipatedLastPeer::APP_UID, $row['APP_UID']);

                $oCriteria->add(ListParticipatedLastPeer::USR_UID, $row['USR_UID']);

                ListParticipatedLastPeer::doDelete($oCriteria);



                $listParticipatedLast = new ListParticipatedLast();

                $listParticipatedLast->create($row);

                $listParticipatedLast = new ListParticipatedLast();

                $listParticipatedLast->refresh($row);

            }



        }



        CLI::logging("> Completed table LIST_INBOX\n");

        //With this List is populated the LIST_PARTICIPATED_HISTORY and LIST_PARTICIPATED_LAST

        CLI::logging("> Completed table LIST_PARTICIPATED_HISTORY\n");

        CLI::logging("> Completed table LIST_PARTICIPATED_LAST\n");



        //Select data TO_DO OR DRAFT CASES CREATED BY AN USER

        $myiCriteria = $appCache->getSelAllColumns();

        $myiCriteria->add(AppCacheViewPeer::DEL_INDEX, "1", CRITERIA::EQUAL);

        $rsCriteria = AppCacheViewPeer::doSelectRS($myiCriteria);

        $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        //Insert new data LIST_MY_INBOX

        while ($rsCriteria->next()) {

              $row = $rsCriteria->getRow();

              $listMyInbox = new ListMyInbox();

              $listMyInbox ->remove($row["APP_UID"],$row["USR_UID"]);

              $listMyInbox->setDeleted(false);

              $listMyInbox->create($row);

        }

        CLI::logging("> Completed table LIST_MY_INBOX\n");



        //Select data PAUSED

        $delaycriteria = new Criteria("workflow");

        $delaycriteria->addSelectColumn(AppDelayPeer::APP_UID);

        $delaycriteria->addSelectColumn(AppDelayPeer::PRO_UID);

        $delaycriteria->addSelectColumn(AppDelayPeer::APP_DEL_INDEX);

        $delaycriteria->addSelectColumn(AppCacheViewPeer::APP_NUMBER);

        $delaycriteria->addSelectColumn(AppCacheViewPeer::USR_UID);

        $delaycriteria->addSelectColumn(AppCacheViewPeer::APP_STATUS);

        $delaycriteria->addSelectColumn(AppCacheViewPeer::TAS_UID);



        $delaycriteria->addJoin( AppCacheViewPeer::APP_UID, AppDelayPeer::APP_UID . ' AND ' . AppCacheViewPeer::DEL_INDEX . ' = ' . AppDelayPeer::APP_DEL_INDEX, Criteria::INNER_JOIN );

        $delaycriteria->add(AppDelayPeer::APP_DISABLE_ACTION_USER, "0", CRITERIA::EQUAL);

        $delaycriteria->add(AppDelayPeer::APP_TYPE, "PAUSE", CRITERIA::EQUAL);

        $rsCriteria = AppDelayPeer::doSelectRS($delaycriteria);

        $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        //Insert new data LIST_PAUSED

        while ($rsCriteria->next()) {

              $row = $rsCriteria->getRow();

              $data = $row;

              $data["DEL_INDEX"] = $row["APP_DEL_INDEX"];

              $listPaused = new ListPaused();

              $listPaused ->remove($row["APP_UID"],$row["APP_DEL_INDEX"],$data);

              $listPaused->setDeleted(false);

              $listPaused->create($data);

        }

        CLI::logging("> Completed table LIST_PAUSED\n");



        //Select and Insert LIST_UNASSIGNED

        $unaCriteria = $appCache->getSelAllColumns();

        $unaCriteria->add(AppCacheViewPeer::USR_UID, "", CRITERIA::EQUAL);

        $rsCriteria = AppCacheViewPeer::doSelectRS($unaCriteria);

        $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        $del = new ListUnassignedPeer();

        $del->doDeleteAll();

        $del = new ListUnassignedGroupPeer();

        $del->doDeleteAll();

        while ($rsCriteria->next()) {

            $row = $rsCriteria->getRow();

            $listUnassigned = new ListUnassigned();

            $unaUid = $listUnassigned->generateData($row["APP_UID"],$row["PREVIOUS_USR_UID"]);

        }

        CLI::logging("> Completed table LIST_UNASSIGNED\n");

        CLI::logging("> Completed table LIST_UNASSIGNED_GROUP\n");



        // ADD LISTS COUNTS

        $aTypes = array(

            'to_do',

            'draft',

            'cancelled',

            'sent',

            'paused',

            'completed',

            'selfservice'

        );



        $users = new Users();

        $criteria = new Criteria();

        $criteria->addSelectColumn(UsersPeer::USR_UID);

        $dataset = UsersPeer::doSelectRS($criteria);

        $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        while($dataset->next()) {

            $aRow = $dataset->getRow();

            $oAppCache = new AppCacheView();

            $aCount = $oAppCache->getAllCounters( $aTypes, $aRow['USR_UID'] );

            $newData = array(

                'USR_UID'                   => $aRow['USR_UID'],

                'USR_TOTAL_INBOX'           => $aCount['to_do'],

                'USR_TOTAL_DRAFT'           => $aCount['draft'],

                'USR_TOTAL_CANCELLED'       => $aCount['cancelled'],

                'USR_TOTAL_PARTICIPATED'    => $aCount['sent'],

                'USR_TOTAL_PAUSED'          => $aCount['paused'],

                'USR_TOTAL_COMPLETED'       => $aCount['completed'],

                'USR_TOTAL_UNASSIGNED'      => $aCount['selfservice']

            );

            $users->update($newData);

        }

        $this->listFirstExecution('insert');

        return true;

    }