Author: Sebastian Bergmann Date: 2007-01-16 10:41:36 +0100 (Tue, 16 Jan 2007) New Revision: 4512
Log: - Remove code duplication. - Add missing doc comment. - Whitespace fixes. Added: experimental/WorkflowDatabaseTiein/src/util.php Modified: experimental/WorkflowDatabaseTiein/src/definition.php experimental/WorkflowDatabaseTiein/src/execution.php experimental/WorkflowDatabaseTiein/src/workflow_database_autoload.php Modified: experimental/WorkflowDatabaseTiein/src/definition.php =================================================================== --- experimental/WorkflowDatabaseTiein/src/definition.php 2007-01-16 09:15:37 UTC (rev 4511) +++ experimental/WorkflowDatabaseTiein/src/definition.php 2007-01-16 09:41:36 UTC (rev 4512) @@ -44,6 +44,7 @@ * * @param integer $workflowId * @param string $workflowName + * @param integer $workflowVersion * @return ezcWorkflow * @throws ezcWorkflowDefinitionException * @throws ezcDbException @@ -58,9 +59,7 @@ $query->select( 'workflow_name, workflow_version' ) ->from( 'workflow' ) ->where( $query->expr->eq( 'workflow_id', - $query->bindValue( $workflowId ) - ) - ); + $query->bindValue( $workflowId ) ) ); $stmt = $query->prepare(); $stmt->execute(); @@ -86,9 +85,7 @@ $query->select( 'node_id, node_class, node_configuration' ) ->from( 'node' ) ->where( $query->expr->eq( 'workflow_id', - $query->bindValue( $workflowId ) - ) - ); + $query->bindValue( $workflowId ) ) ); $stmt = $query->prepare(); $stmt->execute(); @@ -132,22 +129,15 @@ $query = $this->db->createSelectQuery(); $query->select( $query->alias( 'node_connection.incoming_node_id', - 'incoming_node_id' - ) - ) + 'incoming_node_id' ) ) ->select( $query->alias( 'node_connection.outgoing_node_id', - 'outgoing_node_id' - ) - ) + 'outgoing_node_id' ) ) ->from( $query->innerJoin( 'node_connection', 'node', 'node_connection.incoming_node_id', - 'node.node_id' - ) - ) + 'node.node_id' ) ) ->where( $query->expr->eq( 'node.workflow_id', - $query->bindValue( $workflowId ) - ) ); + $query->bindValue( $workflowId ) ) ); $stmt = $query->prepare(); $stmt->execute(); @@ -187,9 +177,7 @@ $query->select( 'variable, class' ) ->from( 'variable_handler' ) ->where( $query->expr->eq( 'workflow_id', - $query->bindValue( $workflowId ) - ) - ); + $query->bindValue( $workflowId ) ) ); $stmt = $query->prepare(); $stmt->execute(); @@ -238,25 +226,18 @@ $query->select( 'workflow_id' ) ->from( 'workflow' ) ->where( $query->expr->eq( 'workflow_name', - $query->bindValue( $workflowName ) - ) - ); + $query->bindValue( $workflowName ) ) ); if ( $workflowVersion == 0 ) { // Load the latest version of the workflow definition by default. - $query->where( $query->expr->eq( 'workflow_version_is_latest', - 1 - ) - ); + $query->where( $query->expr->eq( 'workflow_version_is_latest', 1 ) ); } else { // Load the specified version of the workflow. $query->where( $query->expr->eq( 'workflow_version', - $query->bindValue( $workflowVersion ) - ) - ); + $query->bindValue( $workflowVersion ) ) ); } $stmt = $query->prepare(); @@ -336,16 +317,10 @@ $query = $this->db->createInsertQuery(); $nodeClass = $query->bindValue( get_class( $node ) ); + $nodeConfiguration = $query->bindValue( + ezcWorkflowDatabaseUtil::serialize( $node->getConfiguration() ) + ); - $nodeConfiguration = serialize( $node->getConfiguration() ); - - if ( $nodeConfiguration == 's:0:"";' ) - { - $nodeConfiguration = ''; - } - - $nodeConfiguration = $query->bindValue( $nodeConfiguration ); - $query->insertInto( 'node' ) ->set( 'workflow_id', $workflow->getId() ) ->set( 'node_class', $nodeClass ) @@ -396,11 +371,11 @@ /** * Returns the current version number for a given workflow name. * - * @param string $name + * @param string $workflowName * @return integer * @throws ezcDbException */ - protected function getCurrentVersionNumber( $name ) + protected function getCurrentVersionNumber( $workflowName ) { $query = $this->db->createSelectQuery(); @@ -408,9 +383,7 @@ 'version' ) ) ->from( 'workflow' ) ->where( $query->expr->eq( 'workflow_name', - $query->bindValue( $name ) - ) - ); + $query->bindValue( $workflowName ) ) ); $stmt = $query->prepare(); $stmt->execute(); Modified: experimental/WorkflowDatabaseTiein/src/execution.php =================================================================== --- experimental/WorkflowDatabaseTiein/src/execution.php 2007-01-16 09:15:37 UTC (rev 4511) +++ experimental/WorkflowDatabaseTiein/src/execution.php 2007-01-16 09:41:36 UTC (rev 4512) @@ -70,9 +70,9 @@ $query->update( 'execution' ) ->where( $query->expr->eq( 'execution_id', $this->id ) ) - ->set( 'execution_variables', $query->bindValue( $this->serialize( $this->variables ) ) ) - ->set( 'execution_waiting_for', $query->bindValue( $this->serialize( $this->waitingFor ) ) ) - ->set( 'execution_threads', $query->bindValue( $this->serialize( $this->threads ) ) ) + ->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', $this->nextThreadId ); $statement = $query->prepare(); @@ -85,7 +85,7 @@ $query->insertInto( 'execution_state' ) ->set( 'execution_id', $this->id ) ->set( 'node_id', $node->getId() ) - ->set( 'node_state', $query->bindValue( $this->serialize( $node->getState() ) ) ) + ->set( 'node_state', $query->bindValue( ezcWorkflowDatabaseUtil::serialize( $node->getState() ) ) ) ->set( 'node_thread_id', $node->getThreadId() ); $statement = $query->prepare(); @@ -256,25 +256,6 @@ } /** - * Wrapper for serialize() that returns an empty string - * for empty arrays and null values. - * - * @param mixed $var - * @return string - */ - protected function serialize( $var ) - { - $var = serialize( $var ); - - if ( $var == 'a:0:{}' || $var == 'N;' ) - { - $var = ''; - } - - return $var; - } - - /** * Cleanup execution / execution_state tables. * * @param string $tableName Added: experimental/WorkflowDatabaseTiein/src/util.php =================================================================== --- experimental/WorkflowDatabaseTiein/src/util.php 2007-01-16 09:15:37 UTC (rev 4511) +++ experimental/WorkflowDatabaseTiein/src/util.php 2007-01-16 09:41:36 UTC (rev 4512) @@ -0,0 +1,38 @@ +<?php +/** + * File containing the ezcWorkflowDatabaseUtil class. + * + * @package WorkflowDatabaseTiein + * @version //autogen// + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * Utility methods for WorkflowDatabaseTiein. + * + * @package WorkflowDatabaseTiein + * @version //autogen// + */ +abstract class ezcWorkflowDatabaseUtil +{ + /** + * Wrapper for serialize() that returns an empty string + * for empty arrays and null values. + * + * @param mixed $var + * @return string + */ + public static function serialize( $var ) + { + $var = serialize( $var ); + + if ( $var == 'a:0:{}' || $var == 'N;' ) + { + $var = ''; + } + + return $var; + } +} +?> Property changes on: experimental/WorkflowDatabaseTiein/src/util.php ___________________________________________________________________ Name: svn:eol-style + native Modified: experimental/WorkflowDatabaseTiein/src/workflow_database_autoload.php =================================================================== --- experimental/WorkflowDatabaseTiein/src/workflow_database_autoload.php 2007-01-16 09:15:37 UTC (rev 4511) +++ experimental/WorkflowDatabaseTiein/src/workflow_database_autoload.php 2007-01-16 09:41:36 UTC (rev 4512) @@ -10,6 +10,7 @@ */ return array( 'ezcWorkflowDatabaseDefinition' => 'WorkflowDatabaseTiein/definition.php', - 'ezcWorkflowDatabaseExecution' => 'WorkflowDatabaseTiein/execution.php' + 'ezcWorkflowDatabaseExecution' => 'WorkflowDatabaseTiein/execution.php', + 'ezcWorkflowDatabaseUtil' => 'WorkflowDatabaseTiein/util.php' ); ?> -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components