public function executeIteration($userId = 0)
    {
        $tracker = $this->loader->getTracker();
        $select  = $tracker->getTokenSelect()->andReceptionCodes([])->onlyCompleted()->onlySucces()->forSurveyId($this->sourceSurveyId)->getSelect()->limit(1);

        $results = $this->db->fetchAll($select);
        $batch   = $this->getBatch();
        $batch->addToCounter('movesteps', -1);
        if (count($results) == 0) {
            $this->_finished = true;

            return;
        }

        /**
         * The real work:
         *   - load the token
         *   - retrieve answers
         *   - change token to point to new survey
         *   - inject answers (based on question_code mappings
         */
        // Load token and retrieve current answers
        $tokenData        = reset($results);
        $token            = $tracker->getToken($tokenData);
        $answers          = $token->getRawAnswers();

        // Change answer codes
        if (!empty($answers)) {
            $convertedAnswers = [];
            foreach ($this->targetFields as $target => $source) {
                if (!empty($source) && array_key_exists($source, $answers)) {
                    $convertedAnswers[$target] = $answers[$source];
                }
            }

            // Create a new token
            $values = [
                'gto_id_survey'       => $this->targetSurveyId,
                ] + $tokenData;

            unset($values['token_status']);

            $newTokenId = $token->createReplacement(sprintf($this->_('Copied from old survey: %s'), $this->sourceSurveyName), $userId, $values);
            $newToken = $tracker->getToken($newTokenId);
            $newToken->getSurvey()->copyTokenToSource($newToken, ''); // Take no language, so we get the default
            $newToken->setRawAnswers($convertedAnswers);
            
            $batch->addToCounter('moved');
            
        } else {
            $batch->addToCounter('notfound');
             
        }

        $token->setReceptionCode($this->movedCode, sprintf($this->_('Copied to new survey: %s'), $this->targetSurveyName), $userId);
    }
public function executeIteration($userId = 0)
    {
        $tracker = $this->loader->getTracker();
        $select  = $tracker->getTokenSelect()->andReceptionCodes([])->onlyCompleted()->onlySucces()->forSurveyId($this->sourceSurveyId)->getSelect()->limit(1);

        $results = $this->db->fetchAll($select);
        $batch   = $this->getBatch();
        $batch->addToCounter('movesteps', -1);
        if (count($results) == 0) {
            $this->_finished = true;

            return;
        }

        /**
         * The real work:
         *   - load the token
         *   - retrieve answers
         *   - change token to point to new survey
         *   - inject answers (based on question_code mappings
         */
        // Load token and retrieve current answers
        $tokenData        = reset($results);
        $token            = $tracker->getToken($tokenData);
        $answers          = $token->getRawAnswers();

        // Change answer codes
        if (!empty($answers)) {
            $convertedAnswers = [];
            foreach ($this->targetFields as $target => $source) {
                if (!empty($source) && array_key_exists($source, $answers)) {
                    $convertedAnswers[$target] = $answers[$source];
                }
            }

            // Create a new token
            $values = [
                'gto_id_survey'       => $this->targetSurveyId,
                ] + $tokenData;

            unset($values['token_status']);

            $newTokenId = $token->createReplacement(sprintf($this->_('Copied from old survey: %s'), $this->sourceSurveyName), $userId, $values);
            $newToken = $tracker->getToken($newTokenId);
            $newToken->getSurvey()->copyTokenToSource($newToken, ''); // Take no language, so we get the default
            $newToken->setRawAnswers($convertedAnswers);
            
            $batch->addToCounter('moved');
            
        } else {
            $batch->addToCounter('notfound');
             
        }

        $token->setReceptionCode($this->movedCode, sprintf($this->_('Copied to new survey: %s'), $this->targetSurveyName), $userId);
    }
public function executeIteration ( $ userId = 0 ) { $ tracker = $ this -> loader -> getTracker ( ) ; $ select = $ tracker -> getTokenSelect ( ) -> andReceptionCodes ( [ ] ) -> onlyCompleted ( ) -> onlySucces ( ) -> forSurveyId ( $ this -> sourceSurveyId ) -> getSelect ( ) -> limit ( 1 ) ; $ results = $ this -> db -> fetchAll ( $ select ) ; $ batch = $ this -> getBatch ( ) ; $ batch -> addToCounter ( 'movesteps' , - 1 ) ; if ( count ( $ results ) == 0 ) { $ this -> _finished = true ; return ; } /**
         * The real work:
         *   - load the token
         *   - retrieve answers
         *   - change token to point to new survey
         *   - inject answers (based on question_code mappings
         */ // Load token and retrieve current answers $ tokenData = reset ( $ results ) ; $ token = $ tracker -> getToken ( $ tokenData ) ; $ answers = $ token -> getRawAnswers ( ) ; // Change answer codes if ( ! empty ( $ answers ) ) { $ convertedAnswers = [ ] ; foreach ( $ this -> targetFields as $ target => $ source ) { if ( ! empty ( $ source ) && array_key_exists ( $ source , $ answers ) ) { $ convertedAnswers [ $ target ] = $ answers [ $ source ] ; } } // Create a new token $ values = [ 'gto_id_survey' => $ this -> targetSurveyId , ] + $ tokenData ; unset ( $ values [ 'token_status' ] ) ; $ newTokenId = $ token -> createReplacement ( sprintf ( $ this -> _ ( 'Copied from old survey: %s' ) , $ this -> sourceSurveyName ) , $ userId , $ values ) ; $ newToken = $ tracker -> getToken ( $ newTokenId ) ; $ newToken -> getSurvey ( ) -> copyTokenToSource ( $ newToken , '' ) ; // Take no language, so we get the default $ newToken -> setRawAnswers ( $ convertedAnswers ) ; $ batch -> addToCounter ( 'moved' ) ; } else { $ batch -> addToCounter ( 'notfound' ) ; } $ token -> setReceptionCode ( $ this -> movedCode , sprintf ( $ this -> _ ( 'Copied to new survey: %s' ) , $ this -> targetSurveyName ) , $ userId ) ; }
Execute a single iteration of the task.

@param array $params The parameters to the execute function
Execute a single iteration of the task .