/** * @dataProvider insertIfNotExistsViolatingThrows * @expectedException \Doctrine\DBAL\Exception\UniqueConstraintViolationException * * @param array $compareKeys */ public function testInsertIfNotExistsViolatingThrows($compareKeys) { $result = \OCP\DB::insertIfNotExist('*PREFIX*' . $this->table5, array('storage' => 1, 'path_hash' => md5('welcome.txt'), 'etag' => $this->getUniqueID())); $this->assertEquals(1, $result); $result = \OCP\DB::insertIfNotExist('*PREFIX*' . $this->table5, array('storage' => 1, 'path_hash' => md5('welcome.txt'), 'etag' => $this->getUniqueID()), $compareKeys); $this->assertEquals(0, $result); }
/** * Creates a tag/object relation. * * @param int $objid The id of the object * @param string $tag The id or name of the tag * @return boolean Returns false on error. */ public function tagAs($objid, $tag) { if (is_string($tag) && !is_numeric($tag)) { $tag = trim($tag); if ($tag === '') { \OCP\Util::writeLog('core', __METHOD__ . ', Cannot add an empty tag', \OCP\Util::DEBUG); return false; } if (!$this->hasTag($tag)) { $this->add($tag); } $tagId = $this->getTagId($tag); } else { $tagId = $tag; } try { \OCP\DB::insertIfNotExist(self::RELATION_TABLE, array('objid' => $objid, 'categoryid' => $tagId, 'type' => $this->type)); } catch (\Exception $e) { \OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } return true; }