<commit_before><?php
/**
 * File containing the ezcWorkflowDatabaseExecution class.
 *
 * @category Workflow
 * @package WorkflowDatabaseTiein
 * @version //autogen//
 * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 */

/**
 * Workflow executer that suspends and resumes workflow
 * execution states to and from a database.
 *
 * @package WorkflowDatabaseTiein
 * @version //autogen//
 */
class ezcWorkflowDatabaseExecution extends ezcWorkflowExecution
{
    /**
     * ezcDbHandler instance to be used.
     *
     * @var ezcDbHandler
     */
    protected $db;

    /**
     * Flag that indicates whether the execution has been loaded.
     *
     * @var boolean
     */
    protected $loaded = false;

    /**
     * Construct a new database execution.
     *
     * This constructor is a tie-in.
     *
     * @param ezcDbHandler $db
     * @param int $executionId
     */
    public function __construct ( ezcDbHandler $db, $executionId = null )
    {
        $this->db = $db;

        if ( is_int( $executionId ) )
        {
            $this->loadExecution( $executionId );
        }

        $this->properties['definitionStorage'] = new ezcWorkflowDatabaseDefinitionStorage( $db );
    }

    /**
     * Start workflow execution.
     *
     * @param  int $parentId
     * @throws ezcDbException
     */
    protected function doStart( $parentId )
    {
        $this->db->beginTransaction();

        $query = $this->db->createInsertQuery();

        $query->insertInto( 'execution' )
              ->set( 'workflow_id',       $query->bindValue( (int)$this->workflow->id ) )
              ->set( 'execution_parent',  $query->bindValue( (int)$parentId ) )
              ->set( 'execution_started', $query->bindValue( time() ) )
              ->set( 'execution_variables', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->variables ) ) )
              ->set( 'execution_waiting_for', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->waitingFor ) ) )
              ->set( 'execution_threads', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->threads ) ) )
              ->set( 'execution_next_thread_id', $query->bindValue( (int)$this->nextThreadId ) );

        $statement = $query->prepare();
        $statement->execute();

        $this->id = (int)$this->db->lastInsertId( 'execution_execution_id_seq' );
    }

    /**
     * Suspend workflow execution.
     *
     * @throws ezcDbException
     */
    protected function doSuspend()
    {
        $query = $this->db->createUpdateQuery();

        $query->update( 'execution' )
              ->where( $query->expr->eq( 'execution_id', $query->bindValue( (int)$this->id ) ) )
              ->set( 'execution_variables', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->variables ) ) )
              ->set( 'execution_waiting_for', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->waitingFor ) ) )
              ->set( 'execution_threads', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->threads ) ) )
              ->set( 'execution_next_thread_id', $query->bindValue( (int)$this->nextThreadId ) );

        $statement = $query->prepare();
        $statement->execute();

        foreach ( $this->activatedNodes as $node )
        {
            $query = $this->db->createInsertQuery();

            $query->insertInto( 'execution_state' )
                  ->set( 'execution_id',        $query->bindValue( (int)$this->id ) )
                  ->set( 'node_id',             $query->bindValue( (int)$node->getId() ) )
                  ->set( 'node_state',          $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $node->getState() ) ) )
                  ->set( 'node_activated_from', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $node->getActivatedFrom() ) ) )
                  ->set( 'node_thread_id',      $query->bindValue( (int)$node->getThreadId() ) );

            $statement = $query->prepare();
            $statement->execute();
        }

        $this->db->commit();
    }

    /**
     * Resume workflow execution.
     *
     * @throws ezcDbException
     */
    protected function doResume()
    {
        $this->db->beginTransaction();
        $this->cleanupTable( 'execution_state' );
    }

    /**<commit_msg>- Fix issues reported by PHP_CodeSniffer.<commit_after><?php
/**
 * File containing the ezcWorkflowDatabaseExecution class.
 *
 * @category Workflow
 * @package WorkflowDatabaseTiein
 * @version //autogen//
 * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 */

/**
 * Workflow executer that suspends and resumes workflow
 * execution states to and from a database.
 *
 * @package WorkflowDatabaseTiein
 * @version //autogen//
 */
class ezcWorkflowDatabaseExecution extends ezcWorkflowExecution
{
    /**
     * ezcDbHandler instance to be used.
     *
     * @var ezcDbHandler
     */
    protected $db;

    /**
     * Flag that indicates whether the execution has been loaded.
     *
     * @var boolean
     */
    protected $loaded = false;

    /**
     * Construct a new database execution.
     *
     * This constructor is a tie-in.
     *
     * @param ezcDbHandler $db
     * @param int $executionId
     */
    public function __construct ( ezcDbHandler $db, $executionId = null )
    {
        $this->db = $db;

        if ( is_int( $executionId ) )
        {
            $this->loadExecution( $executionId );
        }

        $this->properties['definitionStorage'] = new ezcWorkflowDatabaseDefinitionStorage( $db );
    }

    /**
     * Start workflow execution.
     *
     * @param  int $parentId
     * @throws ezcDbException
     */
    protected function doStart( $parentId )
    {
        $this->db->beginTransaction();

        $query = $this->db->createInsertQuery();

        $query->insertInto( 'execution' )
              ->set( 'workflow_id', $query->bindValue( (int)$this->workflow->id ) )
              ->set( 'execution_parent', $query->bindValue( (int)$parentId ) )
              ->set( 'execution_started', $query->bindValue( time() ) )
              ->set( 'execution_variables', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->variables ) ) )
              ->set( 'execution_waiting_for', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->waitingFor ) ) )
              ->set( 'execution_threads', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->threads ) ) )
              ->set( 'execution_next_thread_id', $query->bindValue( (int)$this->nextThreadId ) );

        $statement = $query->prepare();
        $statement->execute();

        $this->id = (int)$this->db->lastInsertId( 'execution_execution_id_seq' );
    }

    /**
     * Suspend workflow execution.
     *
     * @throws ezcDbException
     */
    protected function doSuspend()
    {
        $query = $this->db->createUpdateQuery();

        $query->update( 'execution' )
              ->where( $query->expr->eq( 'execution_id', $query->bindValue( (int)$this->id ) ) )
              ->set( 'execution_variables', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->variables ) ) )
              ->set( 'execution_waiting_for', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->waitingFor ) ) )
              ->set( 'execution_threads', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $this->threads ) ) )
              ->set( 'execution_next_thread_id', $query->bindValue( (int)$this->nextThreadId ) );

        $statement = $query->prepare();
        $statement->execute();

        foreach ( $this->activatedNodes as $node )
        {
            $query = $this->db->createInsertQuery();

            $query->insertInto( 'execution_state' )
                  ->set( 'execution_id', $query->bindValue( (int)$this->id ) )
                  ->set( 'node_id', $query->bindValue( (int)$node->getId() ) )
                  ->set( 'node_state', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $node->getState() ) ) )
                  ->set( 'node_activated_from', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $node->getActivatedFrom() ) ) )
                  ->set( 'node_thread_id', $query->bindValue( (int)$node->getThreadId() ) );

            $statement = $query->prepare();
            $statement->execute();
        }

        $this->db->commit();
    }

    /**
     * Resume workflow execution.
     *
     * @throws ezcDbException
     */
    protected function doResume()
    {
        $this->db->beginTransaction();
        $this->cleanupTable( 'execution_state' );
    }

    /**
{'fraction_non_alphanumeric': 0.1508482347546997, 'fraction_numerical': 0.0018340210912425492, 'mean_word_length': 2.440457413249211, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 165, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1154986', 'n_tokens_mistral': 2650, 'n_tokens_neox': 2496, 'n_words': 493}