Author: sb
Date: Tue Jul 31 10:30:43 2007
New Revision: 5768

Log:
- Remove superfluous database checks. I cannot think of any way to make
  these assertions fail with the exception of (intentional) corruption
  of the data in the database which is outside of the scope of the
  component.
# 100% code coverage for ezcWorkflowDatabaseDefinitionStorage.

Modified:
    trunk/WorkflowDatabaseTiein/src/definition_storage.php

Modified: trunk/WorkflowDatabaseTiein/src/definition_storage.php
==============================================================================
--- trunk/WorkflowDatabaseTiein/src/definition_storage.php [iso-8859-1] 
(original)
+++ trunk/WorkflowDatabaseTiein/src/definition_storage.php [iso-8859-1] Tue Jul 
31 10:30:43 2007
@@ -94,106 +94,88 @@
         $result = $stmt->fetchAll( PDO::FETCH_ASSOC );
         $nodes  = array();
 
+        // Create node objects.
+        foreach ( $result as $node )
+        {
+            $nodes[$node['node_id']] = new $node['node_class'](
+              ezcWorkflowDatabaseUtil::unserialize( 
$node['node_configuration'], '' )
+            );
+
+            $nodes[$node['node_id']]->setId( $node['node_id'] );
+
+            if ( $node['node_class'] == 'ezcWorkflowNodeStart' )
+            {
+                $startNode = $nodes[$node['node_id']];
+            }
+
+            else if ( $node['node_class'] == 'ezcWorkflowNodeEnd' &&
+                      !isset( $defaultEndNode ) )
+            {
+                $defaultEndNode = $nodes[$node['node_id']];
+            }
+        }
+
+        // Connect node objects.
+        $query = $this->db->createSelectQuery();
+
+        $query->select( $query->alias( 'node_connection.incoming_node_id',
+                                       'incoming_node_id' ) )
+              ->select( $query->alias( 'node_connection.outgoing_node_id',
+                                       'outgoing_node_id' ) )
+              ->from( $query->innerJoin( 'node_connection',
+                                         'node',
+                                         'node_connection.incoming_node_id',
+                                         'node.node_id' ) )
+              ->where( $query->expr->eq( 'node.workflow_id',
+                                         $query->bindValue( (int)$workflowId ) 
) );
+
+        $stmt = $query->prepare();
+        $stmt->execute();
+
+        $connections = $stmt->fetchAll( PDO::FETCH_ASSOC );
+
+        foreach ( $connections as $connection )
+        {
+            $nodes[$connection['incoming_node_id']]->addOutNode(
+              $nodes[$connection['outgoing_node_id']]
+            );
+        }
+
+        // Create workflow object and add the node objects to it.
+        $workflow = new ezcWorkflow( $workflowName, $startNode, 
$defaultEndNode );
+        $workflow->definitionStorage = $this;
+        $workflow->id = (int)$workflowId;
+        $workflow->version = (int)$workflowVersion;
+
+        // Query the database for the variable handlers.
+        $query = $this->db->createSelectQuery();
+
+        $query->select( 'variable, class' )
+              ->from( 'variable_handler' )
+              ->where( $query->expr->eq( 'workflow_id',
+                                         $query->bindValue( (int)$workflowId ) 
) );
+
+        $stmt = $query->prepare();
+        $stmt->execute();
+
+        $result = $stmt->fetchAll( PDO::FETCH_ASSOC );
+        $nodes  = array();
+
         if ( $result !== false )
         {
-            // Create node objects.
-            foreach ( $result as $node )
-            {
-                $nodes[$node['node_id']] = new $node['node_class'](
-                  ezcWorkflowDatabaseUtil::unserialize( 
$node['node_configuration'], '' )
+            foreach ( $result as $variableHandler )
+            {
+                $workflow->addVariableHandler(
+                  $variableHandler['variable'],
+                  $variableHandler['class']
                 );
-
-                $nodes[$node['node_id']]->setId( $node['node_id'] );
-
-                if ( $node['node_class'] == 'ezcWorkflowNodeStart' )
-                {
-                    $startNode = $nodes[$node['node_id']];
-                }
-
-                else if ( $node['node_class'] == 'ezcWorkflowNodeEnd' &&
-                          !isset( $defaultEndNode ) )
-                {
-                    $defaultEndNode = $nodes[$node['node_id']];
-                }
-            }
-
-            // Connect node objects.
-            $query = $this->db->createSelectQuery();
-
-            $query->select( $query->alias( 'node_connection.incoming_node_id',
-                                           'incoming_node_id' ) )
-                  ->select( $query->alias( 'node_connection.outgoing_node_id',
-                                           'outgoing_node_id' ) )
-                  ->from( $query->innerJoin( 'node_connection',
-                                             'node',
-                                             
'node_connection.incoming_node_id',
-                                             'node.node_id' ) )
-                  ->where( $query->expr->eq( 'node.workflow_id',
-                                              $query->bindValue( 
(int)$workflowId ) ) );
-
-            $stmt = $query->prepare();
-            $stmt->execute();
-
-            $connections = $stmt->fetchAll( PDO::FETCH_ASSOC );
-
-            if ( $connections !== false )
-            {
-                foreach ( $connections as $connection )
-                {
-                    $nodes[$connection['incoming_node_id']]->addOutNode(
-                        $nodes[$connection['outgoing_node_id']]
-                    );
-                }
-            }
-            else
-            {
-                throw new ezcWorkflowDefinitionStorageException(
-                    'Could not load workflow definition.'
-                );
-            }
-
-            // Create workflow object and add the node objects to it.
-            $workflow = new ezcWorkflow( $workflowName, $startNode, 
$defaultEndNode );
-            $workflow->definitionStorage = $this;
-            $workflow->id = (int)$workflowId;
-            $workflow->version = (int)$workflowVersion;
-
-            // Query the database for the variable handlers.
-            $query = $this->db->createSelectQuery();
-
-            $query->select( 'variable, class' )
-                  ->from( 'variable_handler' )
-                  ->where( $query->expr->eq( 'workflow_id',
-                                              $query->bindValue( 
(int)$workflowId ) ) );
-
-            $stmt = $query->prepare();
-            $stmt->execute();
-
-            $result = $stmt->fetchAll( PDO::FETCH_ASSOC );
-            $nodes  = array();
-
-            if ( $result !== false )
-            {
-                foreach ( $result as $variableHandler )
-                {
-                    $workflow->addVariableHandler(
-                      $variableHandler['variable'],
-                      $variableHandler['class']
-                    );
-                }
-            }
-
-            // Verify the loaded workflow.
-            $workflow->verify();
-
-            return $workflow;
-        }
-        else
-        {
-            throw new ezcWorkflowDefinitionStorageException(
-              'Could not load workflow definition.'
-            );
-        }
+            }
+        }
+
+        // Verify the loaded workflow.
+        $workflow->verify();
+
+        return $workflow;
     }
 
     /**


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to