diff --git a/composer.json b/composer.json index 5f7cce0ac4..9f11bca5b2 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ "php-xpdf/php-xpdf" : "~0.2.1", "phpexiftool/phpexiftool" : "~0.3", "react/zmq" : "~0.2", + "rhumsaa/uuid" : "~2.7", "silex/silex" : "1.1.x-dev@dev", "silex/web-profiler" : "~1.0.0@dev", "sorien/silex-dbal-profiler" : "~1.0.0", diff --git a/composer.lock b/composer.lock index 77a69c158b..5df66f544b 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "86007d19092732cf77a4dab27e072a2b", + "hash": "0d8e038306a0c58deac6187e6a607e71", "packages": [ { "name": "alchemy-fr/tcpdf-clone", @@ -3220,6 +3220,71 @@ ], "time": "2013-09-18 11:02:06" }, + { + "name": "rhumsaa/uuid", + "version": "2.7.1", + "source": { + "type": "git", + "url": "https://github.com/ramsey/uuid.git", + "reference": "8569983a11ed96087cdf94c7aa65866138681beb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/8569983a11ed96087cdf94c7aa65866138681beb", + "reference": "8569983a11ed96087cdf94c7aa65866138681beb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "doctrine/dbal": ">=2.3", + "moontoast/math": "~1.1", + "phpunit/phpunit": "~3.7", + "symfony/console": "~2.3" + }, + "suggest": { + "doctrine/dbal": "Allow the use of a UUID as doctrine field type.", + "moontoast/math": "Support for converting UUID to 128-bit integer (in string form).", + "symfony/console": "Support for use of the bin/uuid command line tool." + }, + "bin": [ + "bin/uuid" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7.x-dev" + } + }, + "autoload": { + "psr-0": { + "Rhumsaa\\Uuid": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marijn Huizendveld", + "email": "marijn.huizendveld@gmail.com" + }, + { + "name": "Ben Ramsey", + "homepage": "http://benramsey.com" + } + ], + "description": "A PHP 5.3+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).", + "homepage": "https://github.com/ramsey/uuid", + "keywords": [ + "guid", + "identifier", + "uuid" + ], + "time": "2014-02-22 00:08:43" + }, { "name": "silex/silex", "version": "1.1.x-dev", diff --git a/lib/Alchemy/Phrasea/Border/File.php b/lib/Alchemy/Phrasea/Border/File.php index 60bbf3b517..532299fe02 100644 --- a/lib/Alchemy/Phrasea/Border/File.php +++ b/lib/Alchemy/Phrasea/Border/File.php @@ -26,6 +26,7 @@ use PHPExiftool\Driver\Metadata\Metadata; use PHPExiftool\Driver\Metadata\MetadataBag as ExiftoolMetadataBag; use PHPExiftool\Driver\Value\Mono as MonoValue; use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException; +use Rhumsaa\Uuid\Uuid; /** * Phraseanet candidate File package @@ -112,7 +113,7 @@ class File foreach ($availableUUIDs as $meta) { if ($metadatas->containsKey($meta)) { $candidate = $metadatas->get($meta)->getValue()->asString(); - if (\uuid::is_valid($candidate)) { + if (Uuid::isValid($candidate)) { $uuid = $candidate; break; } @@ -120,10 +121,7 @@ class File } if (! $uuid && $generate) { - /** - * @todo Check if a file exists with the same checksum - */ - $uuid = \uuid::generate_v4(); + $uuid = Uuid::uuid4(); } $this->uuid = $uuid; diff --git a/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php b/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php index d75b646f3c..58402404c7 100644 --- a/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php +++ b/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Command\Upgrade; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Border\File; +use Rhumsaa\Uuid\Uuid; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -121,7 +122,7 @@ class Step31 implements DatasUpgraderInterface { $pathfile = \p4string::addEndSlash($record['path']) . $record['file']; - $uuid = \uuid::generate_v4(); + $uuid = Uuid::uuid4(); try { $media = $this->app['mediavorus']->guess($pathfile); $collection = \collection::get_from_coll_id($app, $databox, (int) $record['coll_id']); diff --git a/lib/classes/Bridge/Api/Youtube.php b/lib/classes/Bridge/Api/Youtube.php index cb5c53f203..e5a82ec640 100644 --- a/lib/classes/Bridge/Api/Youtube.php +++ b/lib/classes/Bridge/Api/Youtube.php @@ -9,6 +9,7 @@ * file that was distributed with this source code. */ +use Rhumsaa\Uuid\Uuid; use Symfony\Component\HttpFoundation\Request; class Bridge_Api_Youtube extends Bridge_Api_Abstract implements Bridge_Api_Interface @@ -829,7 +830,7 @@ class Bridge_Api_Youtube extends Bridge_Api_Abstract implements Bridge_Api_Inter $this->_api = new Zend_Gdata_YouTube( $http_client, - uuid::generate_v4(), + Uuid::uuid4(), $this->conf->get(['main', 'bridge', 'youtube', 'client_id']), $this->conf->get(['main', 'bridge', 'youtube', 'developer_key'])); $this->_api->setMajorProtocolVersion(2); diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index c60e5843ba..96643cf109 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -19,6 +19,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Doctrine\ORM\EntityManager; use MediaVorus\MediaVorus; +use Rhumsaa\Uuid\Uuid; use Symfony\Component\HttpFoundation\File\File as SymfoFile; class record_adapter implements record_Interface, cache_cacheableInterface @@ -1190,7 +1191,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface ':parent_record_id' => 1, ':type' => 'unknown', ':sha256' => null, - ':uuid' => \uuid::generate_v4(), + ':uuid' => Uuid::uuid4(), ':originalname' => null, ':mime' => null, ]); diff --git a/lib/classes/uuid.php b/lib/classes/uuid.php deleted file mode 100644 index eaf383db5f..0000000000 --- a/lib/classes/uuid.php +++ /dev/null @@ -1,154 +0,0 @@ -uuid2 - */ - public static function compare($uuid1, $uuid2) - { - return (strcmp($uuid1, $uuid2) === 0); - } - - /** - * @desc Check wheter an UUID is the NULL UUID 00000000-0000-0000-0000-000000000000 - * @return string - */ - public static function is_null($uuid) - { - return (0 === strcmp($uuid, '00000000-0000-0000-0000-000000000000')); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Border/FileTest.php b/tests/Alchemy/Tests/Phrasea/Border/FileTest.php index f560ac127e..8d2aef2773 100644 --- a/tests/Alchemy/Tests/Phrasea/Border/FileTest.php +++ b/tests/Alchemy/Tests/Phrasea/Border/FileTest.php @@ -15,6 +15,7 @@ use PHPExiftool\Driver\Tag\IPTC\Keywords; use PHPExiftool\Driver\Value\Multi; use PHPExiftool\Driver\Metadata\Metadata as PHPExiftoolMetadata; use Alchemy\Phrasea\Border\Attribute\Metadata; +use Rhumsaa\Uuid\Uuid; class FileTest extends \PhraseanetTestCase { @@ -75,20 +76,20 @@ class FileTest extends \PhraseanetTestCase $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']); $uuid = $borderFile->getUUID(true, false); - $this->assertTrue(\uuid::is_valid($uuid)); + $this->assertTrue(Uuid::isValid($uuid)); $this->assertEquals($uuid, $borderFile->getUUID()); $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']); $newuuid = $borderFile->getUUID(true, true); - $this->assertTrue(\uuid::is_valid($newuuid)); + $this->assertTrue(Uuid::isValid($newuuid)); $this->assertNotEquals($uuid, $newuuid); $this->assertEquals($newuuid, $borderFile->getUUID()); $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']); $uuid = $borderFile->getUUID(); - $this->assertTrue(\uuid::is_valid($uuid)); + $this->assertTrue(Uuid::isValid($uuid)); $this->assertEquals($uuid, $newuuid); $this->assertEquals($uuid, $borderFile->getUUID()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php index e4c426a3b4..22d0c3d448 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php @@ -5,6 +5,7 @@ namespace Alchemy\Tests\Phrasea\Controller\Admin; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Border\File; +use Rhumsaa\Uuid\Uuid; class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { @@ -540,7 +541,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase ':parent_record_id' => 0, ':type' => 'unknown', ':sha256' => null, - ':uuid' => \uuid::generate_v4(), + ':uuid' => Uuid::uuid4(), ':originalname' => null, ':mime' => null, ]); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php index 1af799194b..1417ba867a 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php @@ -4,6 +4,7 @@ namespace Alchemy\Tests\Phrasea\Controller\Admin; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Border\File; +use Rhumsaa\Uuid\Uuid; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class DataboxTest extends \PhraseanetAuthenticatedWebTestCase @@ -658,7 +659,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase ':parent_record_id' => 0, ':type' => 'unknown', ':sha256' => null, - ':uuid' => \uuid::generate_v4(), + ':uuid' => Uuid::uuid4(), ':originalname' => null, ':mime' => null, ]); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php index a6bf119102..b215690712 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiTestCase.php @@ -11,6 +11,7 @@ use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\LazaretSession; use Doctrine\Common\Collections\ArrayCollection; use Guzzle\Common\Exception\GuzzleException; +use Rhumsaa\Uuid\Uuid; use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpFoundation\Response; @@ -2175,7 +2176,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase $this->assertTrue(is_string($record['phrasea_type'])); $this->assertTrue(in_array($record['phrasea_type'], ['audio', 'document', 'image', 'video', 'flash', 'unknown'])); $this->assertArrayHasKey('uuid', $record); - $this->assertTrue(\uuid::is_valid($record['uuid'])); + $this->assertTrue(Uuid::isValid($record['uuid'])); if (!is_null($record['thumbnail'])) { $this->assertTrue(is_array($record['thumbnail'])); @@ -2228,7 +2229,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase $this->assertArrayHasKey('uuid', $story); $this->assertArrayHasKey('@entity@', $story); $this->assertEquals(V1::OBJECT_TYPE_STORY, $story['@entity@']); - $this->assertTrue(\uuid::is_valid($story['uuid'])); + $this->assertTrue(Uuid::isValid($story['uuid'])); if ( ! is_null($story['thumbnail'])) { $this->assertTrue(is_array($story['thumbnail'])); diff --git a/tests/classes/record/adapterTest.php b/tests/classes/record/adapterTest.php index a5ac2a096d..9d409d9ee7 100644 --- a/tests/classes/record/adapterTest.php +++ b/tests/classes/record/adapterTest.php @@ -1,5 +1,7 @@ assertTrue(uuid::is_valid(self::$DI['record_1']->get_uuid())); + $this->assertTrue(Uuid::isValid(self::$DI['record_1']->get_uuid())); } public function testGet_modification_date() diff --git a/tests/classes/uuidTest.php b/tests/classes/uuidTest.php deleted file mode 100644 index 8f50aa6f9f..0000000000 --- a/tests/classes/uuidTest.php +++ /dev/null @@ -1,116 +0,0 @@ -object = new uuid(); - } - - public function testGenerate_v3() - { - $datas = []; - for ($i = 0; $i < 1000; $i ++) { - $uuid = uuid::generate_v4(); - - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v4 invalide'); - - $uuid = uuid::generate_v3($uuid, self::$DI['app']['random.low']->generateString(8)); - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v5 invalide'); - - $datas[] = $uuid; - } - - $datas = array_unique($datas); - - if (count($datas) !== 1000) - $this->fail('Generation de deux uuid identiques en v3' . count($datas)); - - unset($datas); - } - - public function testGenerate_v4() - { - $datas = []; - for ($i = 0; $i < 1000; $i ++) { - $uuid = uuid::generate_v4(); - - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v4 invalide'); - - $datas[] = $uuid; - } - - $datas = array_unique($datas); - - if (count($datas) !== 1000) - $this->fail('Generation de deux uuid identiques en v4' . count($datas)); - - unset($datas); - } - - public function testGenerate_v5() - { - $datas = []; - for ($i = 0; $i < 1000; $i ++) { - $uuid = uuid::generate_v4(); - - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v4 invalide'); - - $uuid = uuid::generate_v5($uuid, self::$DI['app']['random.low']->generateString(8)); - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v5 invalide'); - - $datas[] = $uuid; - } - - $datas = array_unique($datas); - - if (count($datas) !== 1000) - $this->fail('Generation de deux uuid identiques en v5' . count($datas)); - - unset($datas); - } - - public function testIs_valid() - { - for ($i = 0; $i < 1000; $i ++) { - $uuid = uuid::generate_v4(); - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v4 invalide'); - - $uuid = uuid::generate_v5($uuid, self::$DI['app']['random.low']->generateString(8)); - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v5 invalide'); - - $uuid = uuid::generate_v3($uuid, self::$DI['app']['random.low']->generateString(8)); - if ( ! uuid::is_valid($uuid)) - $this->fail('Generation d\'un uuid v3 invalide'); - - unset($uuid); - } - } - - public function testCompare() - { - for ($i = 0; $i < 1000; $i ++) { - $uuid1 = uuid::generate_v4(); - $uuid2 = uuid::generate_v4(); - $this->assertFalse(uuid::compare($uuid1, $uuid2)); - } - } - - public function testIs_null() - { - $this->assertTrue(uuid::is_null('00000000-0000-0000-0000-000000000000')); - } -}