In the Mapper->delete() method the $pdoStatement variable is populated from the table->deleteRowPerform() method, which "can" return a PDOStatment, however, the deleteRowPerform() method can "also" output null, which is not an acceptable parameter type in the mapperevents->afterDelete() method.
I believe this might happen if the row in question had already been deleted from the db itself (my db has foreign keys which might be causing this situation), but in that case, if the delete of the row has already happened, then it may be preferable for the code to just "carry on", instead of throwing an exception.
public function delete(Record $record) : void
{
$row = $record->getRow();
$this->mapperEvents->beforeDelete($this, $record);
$this->relationships->fixNativeRecord($record);
$delete = $this->table->deleteRowPrepare($row);
$this->mapperEvents->modifyDelete($this, $record, $delete);
$pdoStatement = $this->table->deleteRowPerform($row, $delete);
$this->relationships->fixForeignRecord($record);
$this->mapperEvents->afterDelete(
$this,
$record,
$delete,
$pdoStatement
);
}
Table->deleteRowPerform() method
public function deleteRowPerform(Row $row, Delete $delete) : ?PDOStatement
{
if ($row->getStatus() === $row::DELETED) {
return null;
}
if (empty(static::PRIMARY_KEY)) {
throw Exception::cannotPerformWithoutPrimaryKey('delete row', static::NAME);
}
$pdoStatement = $delete->perform();
$rowCount = $pdoStatement->rowCount();
if ($rowCount != 1) {
throw Exception::unexpectedRowCountAffected($rowCount);
}
$this->tableEvents->afterDeleteRow($this, $row, $delete, $pdoStatement);
$row->init($row::DELETED);
return $pdoStatement;
}
Mapperevents->afterDelete() method.
public function afterDelete(
Mapper $mapper,
Record $record,
Delete $delete,
PDOStatement $pdoStatement
) : void
{
}
In the Mapper->delete() method the $pdoStatement variable is populated from the table->deleteRowPerform() method, which "can" return a PDOStatment, however, the deleteRowPerform() method can "also" output null, which is not an acceptable parameter type in the mapperevents->afterDelete() method.
I believe this might happen if the row in question had already been deleted from the db itself (my db has foreign keys which might be causing this situation), but in that case, if the delete of the row has already happened, then it may be preferable for the code to just "carry on", instead of throwing an exception.
Table->deleteRowPerform() method
Mapperevents->afterDelete() method.