From 24c7f38a0046a96c43da7953df5833571c6bd1ed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Feb 2016 15:41:21 +0100 Subject: [PATCH] Make sure we can store strings as per the interface --- db_structure.xml | 7 +- .../systemtag/systemtagobjectmapper.php | 4 +- .../systemtag/systemtagobjectmappertest.php | 74 +++++++++---------- version.php | 2 +- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/db_structure.xml b/db_structure.xml index dbbfa8c7a4d..b1242171127 100644 --- a/db_structure.xml +++ b/db_structure.xml @@ -1249,11 +1249,10 @@ objectid - integer - 0 + text + true - true - 4 + 64 diff --git a/lib/private/systemtag/systemtagobjectmapper.php b/lib/private/systemtag/systemtagobjectmapper.php index 1efb4f0f6e0..754184102a9 100644 --- a/lib/private/systemtag/systemtagobjectmapper.php +++ b/lib/private/systemtag/systemtagobjectmapper.php @@ -103,7 +103,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper { $this->assertTagsExist($tagIds); $query = $this->connection->getQueryBuilder(); - $query->select($query->createFunction('DISTINCT(`objectid`)')) + $query->selectDistinct('objectid') ->from(self::RELATION_TABLE) ->where($query->expr()->in('systemtagid', $query->createParameter('tagids'))) ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) @@ -208,7 +208,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper { ->where($query->expr()->in('objectid', $query->createParameter('objectids'))) ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) ->andWhere($query->expr()->eq('systemtagid', $query->createParameter('tagid'))) - ->setParameter('objectids', $objIds, IQueryBuilder::PARAM_INT_ARRAY) + ->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY) ->setParameter('tagid', $tagId) ->setParameter('objecttype', $objectType); diff --git a/tests/lib/systemtag/systemtagobjectmappertest.php b/tests/lib/systemtag/systemtagobjectmappertest.php index 5c8204f6a87..f49917a0265 100644 --- a/tests/lib/systemtag/systemtagobjectmappertest.php +++ b/tests/lib/systemtag/systemtagobjectmappertest.php @@ -102,10 +102,10 @@ class SystemTagObjectMapperTest extends TestCase { return $result; })); - $this->tagMapper->assignTags(1, 'testtype', $this->tag1->getId()); - $this->tagMapper->assignTags(1, 'testtype', $this->tag2->getId()); - $this->tagMapper->assignTags(2, 'testtype', $this->tag1->getId()); - $this->tagMapper->assignTags(3, 'anothertype', $this->tag1->getId()); + $this->tagMapper->assignTags('1', 'testtype', $this->tag1->getId()); + $this->tagMapper->assignTags('1', 'testtype', $this->tag2->getId()); + $this->tagMapper->assignTags('2', 'testtype', $this->tag1->getId()); + $this->tagMapper->assignTags('3', 'anothertype', $this->tag1->getId()); } public function tearDown() { @@ -121,15 +121,15 @@ class SystemTagObjectMapperTest extends TestCase { public function testGetTagsForObjects() { $tagIdMapping = $this->tagMapper->getTagIdsForObjects( - [1, 2, 3, 4], + ['1', '2', '3', '4'], 'testtype' ); $this->assertEquals([ - 1 => [$this->tag1->getId(), $this->tag2->getId()], - 2 => [$this->tag1->getId()], - 3 => [], - 4 => [], + '1' => [$this->tag1->getId(), $this->tag2->getId()], + '2' => [$this->tag1->getId()], + '3' => [], + '4' => [], ], $tagIdMapping); } @@ -140,8 +140,8 @@ class SystemTagObjectMapperTest extends TestCase { ); $this->assertEquals([ - 1, - 2, + '1', + '2', ], $objectIds); } @@ -156,29 +156,29 @@ class SystemTagObjectMapperTest extends TestCase { } public function testAssignUnassignTags() { - $this->tagMapper->unassignTags(1, 'testtype', [$this->tag1->getId()]); + $this->tagMapper->unassignTags('1', 'testtype', [$this->tag1->getId()]); - $tagIdMapping = $this->tagMapper->getTagIdsForObjects(1, 'testtype'); + $tagIdMapping = $this->tagMapper->getTagIdsForObjects('1', 'testtype'); $this->assertEquals([ 1 => [$this->tag2->getId()], ], $tagIdMapping); - $this->tagMapper->assignTags(1, 'testtype', [$this->tag1->getId()]); - $this->tagMapper->assignTags(1, 'testtype', $this->tag3->getId()); + $this->tagMapper->assignTags('1', 'testtype', [$this->tag1->getId()]); + $this->tagMapper->assignTags('1', 'testtype', $this->tag3->getId()); - $tagIdMapping = $this->tagMapper->getTagIdsForObjects(1, 'testtype'); + $tagIdMapping = $this->tagMapper->getTagIdsForObjects('1', 'testtype'); $this->assertEquals([ - 1 => [$this->tag1->getId(), $this->tag2->getId(), $this->tag3->getId()], + '1' => [$this->tag1->getId(), $this->tag2->getId(), $this->tag3->getId()], ], $tagIdMapping); } public function testReAssignUnassignTags() { // reassign tag1 - $this->tagMapper->assignTags(1, 'testtype', [$this->tag1->getId()]); + $this->tagMapper->assignTags('1', 'testtype', [$this->tag1->getId()]); // tag 3 was never assigned - $this->tagMapper->unassignTags(1, 'testtype', [$this->tag3->getId()]); + $this->tagMapper->unassignTags('1', 'testtype', [$this->tag3->getId()]); $this->assertTrue(true, 'No error when reassigning/unassigning'); } @@ -187,13 +187,13 @@ class SystemTagObjectMapperTest extends TestCase { * @expectedException \OCP\SystemTag\TagNotFoundException */ public function testAssignNonExistingTags() { - $this->tagMapper->assignTags(1, 'testtype', [100]); + $this->tagMapper->assignTags('1', 'testtype', [100]); } public function testAssignNonExistingTagInArray() { $caught = false; try { - $this->tagMapper->assignTags(1, 'testtype', [100, $this->tag3->getId()]); + $this->tagMapper->assignTags('1', 'testtype', [100, $this->tag3->getId()]); } catch (TagNotFoundException $e) { $caught = true; } @@ -201,12 +201,12 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertTrue($caught, 'Exception thrown'); $tagIdMapping = $this->tagMapper->getTagIdsForObjects( - [1], + ['1'], 'testtype' ); $this->assertEquals([ - 1 => [$this->tag1->getId(), $this->tag2->getId()], + '1' => [$this->tag1->getId(), $this->tag2->getId()], ], $tagIdMapping, 'None of the tags got assigned'); } @@ -214,13 +214,13 @@ class SystemTagObjectMapperTest extends TestCase { * @expectedException \OCP\SystemTag\TagNotFoundException */ public function testUnassignNonExistingTags() { - $this->tagMapper->unassignTags(1, 'testtype', [100]); + $this->tagMapper->unassignTags('1', 'testtype', [100]); } public function testUnassignNonExistingTagsInArray() { $caught = false; try { - $this->tagMapper->unassignTags(1, 'testtype', [100, $this->tag1->getId()]); + $this->tagMapper->unassignTags('1', 'testtype', [100, $this->tag1->getId()]); } catch (TagNotFoundException $e) { $caught = true; } @@ -233,14 +233,14 @@ class SystemTagObjectMapperTest extends TestCase { ); $this->assertEquals([ - 1 => [$this->tag1->getId(), $this->tag2->getId()], + '1' => [$this->tag1->getId(), $this->tag2->getId()], ], $tagIdMapping, 'None of the tags got unassigned'); } public function testHaveTagAllMatches() { $this->assertTrue( $this->tagMapper->haveTag( - [1], + ['1'], 'testtype', $this->tag1->getId(), true @@ -250,7 +250,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertTrue( $this->tagMapper->haveTag( - [1, 2], + ['1', '2'], 'testtype', $this->tag1->getId(), true @@ -260,7 +260,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertFalse( $this->tagMapper->haveTag( - [1, 2], + ['1', '2'], 'testtype', $this->tag2->getId(), true @@ -270,7 +270,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertFalse( $this->tagMapper->haveTag( - [2], + ['2'], 'testtype', $this->tag2->getId(), true @@ -280,7 +280,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertFalse( $this->tagMapper->haveTag( - [3], + ['3'], 'testtype', $this->tag2->getId(), true @@ -292,7 +292,7 @@ class SystemTagObjectMapperTest extends TestCase { public function testHaveTagAtLeastOneMatch() { $this->assertTrue( $this->tagMapper->haveTag( - [1], + ['1'], 'testtype', $this->tag1->getId(), false @@ -302,7 +302,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertTrue( $this->tagMapper->haveTag( - [1, 2], + ['1', '2'], 'testtype', $this->tag1->getId(), false @@ -312,7 +312,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertTrue( $this->tagMapper->haveTag( - [1, 2], + ['1', '2'], 'testtype', $this->tag2->getId(), false @@ -322,7 +322,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertFalse( $this->tagMapper->haveTag( - [2], + ['2'], 'testtype', $this->tag2->getId(), false @@ -332,7 +332,7 @@ class SystemTagObjectMapperTest extends TestCase { $this->assertFalse( $this->tagMapper->haveTag( - [3], + ['3'], 'testtype', $this->tag2->getId(), false @@ -346,7 +346,7 @@ class SystemTagObjectMapperTest extends TestCase { */ public function testHaveTagNonExisting() { $this->tagMapper->haveTag( - [1], + ['1'], 'testtype', 100 ); diff --git a/version.php b/version.php index dfe5d68300c..4ae94717c3d 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ // We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(9, 0, 0, 12); +$OC_Version = array(9, 0, 0, 13); // The human readable string $OC_VersionString = '9.0.0 beta 2'; -- 2.39.5