/** * @param ActionEventDispatcher $dispatcher */ public function attach(ActionEventDispatcher $dispatcher) { //Used within the test: //DoctrineTableGatewayTest::it_filters_users_by_a_between_filter_set_by_an_action_event_listener $this->trackHandler($dispatcher->attachListener('collect_result_set', [$this, 'onCollectResultSet'])); $this->trackHandler($dispatcher->attachListener('count_rows', [$this, 'onCountRows'])); //Used within the test: //DoctrineTableGatewayTest::it_does_not_perform_the_delete_query_when_no_listener_adds_a_condition $this->trackHandler($dispatcher->attachListener('delete_table_row', [$this, 'onDeleteTableRow'])); self::$isAttached = true; }
/** * @param ActionEventDispatcher $events * * @return void */ public function attach(ActionEventDispatcher $events) { $this->trackHandler($events->attachListener(MessageDispatch::INITIALIZE, [$this, 'onInitializeMessageDispatch'])); $this->trackHandler($events->attachListener(MessageDispatch::FINALIZE, [$this, 'onFinalizeMessageDispatch'])); }
/** * @param ActionEventDispatcher $events * * @return void */ public function attach(ActionEventDispatcher $events) { $this->trackHandler($events->attachListener(MessageDispatch::INITIALIZE, $this)); }
private function updateOrInsertTableRow(TableRow $data, $forceInsert = false, Statement $insertStmt = null) { $id = false; $pk = null; if ($data->description()->hasIdentifier()) { $pk = $data::toDbColumnName($data->description()->identifierName()); $id = $data->property($data->description()->identifierName())->value(); } $dbTypes = $this->getDbTypesForProperties($data); $itemType = $data->prototype()->of(); $data = $this->convertToDbData($data); //In try update mode we try to delete the table row first and then insert it again if (!$forceInsert) { $query = $this->connection->createQueryBuilder(); //Due to Sqlite error when using an alias we don't assign one here, so delete queries are limit to one table //However, a action event listener can rebuild the query and use a platform specific delete with joins if required $query->delete($this->table); if ($id) { $query->where($query->expr()->eq($pk, ':identifier')); $query->setParameter('identifier', $id, $dbTypes[$pk]); } elseif ($this->triggerActions) { $actionEvent = $this->actions->getNewActionEvent('delete_table_row', $this, ['query' => $query, 'item_type' => $itemType, 'item_db_data' => $data, 'item_db_types' => $dbTypes, 'skip_row' => false]); $this->actions->dispatch($actionEvent); if ($actionEvent->getParam('skip_row')) { return $insertStmt; } $query = $actionEvent->getParam('query'); if ($query && empty($query->getQueryPart('where'))) { $query = null; } } else { $query = null; } //We only perform the delete query if it has at least one condition set. if ($query) { $query->execute(); } } return $this->performInsert($data, $dbTypes, $insertStmt); }
/** * Attach to CommandBus or EventBus route event * * @param ActionEventDispatcher $events * * @return void */ public function attach(ActionEventDispatcher $events) { $this->trackHandler($events->attachListener(MessageDispatch::ROUTE, array($this, 'onRouteMessage'), 100)); }