protected function insertRelated(array $rows) { if (!is_array(reset($rows))) { $rows = array($rows); } $trees = array(); foreach ($rows as $key => $row) { $trees[$key] = $this->splitUpdate($row, 'tree'); } $dbw = $this->dbFactory->getDB(DB_MASTER); $res = $dbw->insert($this->joinTable(), $this->preprocessNestedSqlArray($trees), __METHOD__); // If this is a brand new root revision it needs to be added to the tree // If it has a rev_parent_id then its already a part of the tree if ($res) { foreach ($rows as $row) { if ($row['rev_parent_id'] === null) { $res = $res && $this->treeRepo->insert(UUID::create($row['tree_rev_descendant_id']), UUID::create($row['tree_parent_id'])); } } } if (!$res) { return array(); } return $rows; }
/** * @expectedException \Flow\Exception\DataModelException */ public function testFailingInsert() { global $wgFlowCacheTime; // Catch the exception and test the cache result then re-throw the exception, // otherwise the exception would skip the cache result test $cache = new BufferedCache(new BufferedBagOStuff(new \HashBagOStuff()), $wgFlowCacheTime); try { $treeRepository = new TreeRepository($this->mockDbFactory(false), $cache); $this->assertNull($treeRepository->insert($this->descendant, $this->ancestor)); } catch (\Exception $e) { $reflection = new ReflectionClass('\\Flow\\Repository\\TreeRepository'); $method = $reflection->getMethod('cacheKey'); $method->setAccessible(true); $this->assertSame($cache->get($method->invoke($treeRepository, 'rootpath', $this->descendant)), false); $this->assertSame($cache->get($method->invoke($treeRepository, 'parent', $this->descendant)), false); throw $e; } }