/** * Deletes the records in the intermediate table of m:n relations for a * given model. * * @param Tx_Oelib_Model $model the model to delete the records in the * intermediate table of m:n relations for * * @return void */ private function deleteManyToManyRelationIntermediateRecords(Tx_Oelib_Model $model) { foreach (array_keys($this->relations) as $key) { if ($this->isManyToManyRelationConfigured($key)) { $relationConfiguration = $this->getRelationConfigurationFromTca($key); $mnTable = $relationConfiguration['MM']; if (isset($relationConfiguration['MM_opposite_field'])) { $where = 'uid_foreign=' . $model->getUid(); } else { $where = 'uid_local=' . $model->getUid(); } Tx_Oelib_Db::delete($mnTable, $where); } } }
/** * @test */ public function existsExactlyOneRecordIgnoresNonDummyRecords() { Tx_Oelib_Db::insert('tx_oelib_test', array('title' => 'foo')); $testResult = $this->subject->existsExactlyOneRecord('tx_oelib_test', 'title = "foo"'); Tx_Oelib_Db::delete('tx_oelib_test', 'title = "foo"'); // We need to do this manually to not confuse the auto_increment counter // of the testing framework. $this->subject->resetAutoIncrement('tx_oelib_test'); self::assertFalse($testResult); }
/** * @test */ public function deleteForTwoDeletedRecordsReturnsTwo() { $uid1 = $this->testingFramework->createRecord('tx_oelib_test'); $uid2 = $this->testingFramework->createRecord('tx_oelib_test'); self::assertSame(2, Tx_Oelib_Db::delete('tx_oelib_test', 'uid IN(' . $uid1 . ',' . $uid2 . ')')); }
/** * Deletes a set of records that have been added through this framework for * a set of tables (either the test tables or the allowed system tables). * For this, all records with the "is_dummy_record" flag set to 1 will be * deleted from all tables that have been used within this instance of the * testing framework. * * If you set $performDeepCleanUp to TRUE, it will go through ALL tables to * which the current instance of the testing framework has access. Please * consider well, whether you want to do this as it's a huge performance * issue. * * @param bool $useSystemTables whether to clean up the system tables (TRUE) or the non-system test tables (FALSE) * @param bool $performDeepCleanUp whether a deep clean up should be performed, may be empty * * @return void */ protected function cleanUpTableSet($useSystemTables, $performDeepCleanUp) { if ($useSystemTables) { $tablesToCleanUp = $performDeepCleanUp ? $this->allowedSystemTables : $this->dirtySystemTables; } else { $tablesToCleanUp = $performDeepCleanUp ? $this->ownAllowedTables : $this->dirtyTables; } foreach ($tablesToCleanUp as $currentTable) { $dummyColumnName = $this->getDummyColumnName($currentTable); // Runs a delete query for each allowed table. A // "one-query-deletes-them-all" approach was tested but we didn't // find a working solution for that. Tx_Oelib_Db::delete($currentTable, $dummyColumnName . ' = 1'); // Resets the auto increment setting of the current table. $this->resetAutoIncrementLazily($currentTable); } // Resets the list of dirty tables. $this->dirtyTables = array(); }