public function fillCategoryData() { foreach ($this->categories as $category) { if (!($data = $this->modx->getObject('mSkladCategoryData', array('category_id' => $category['id'])))) { $data = $this->modx->newObject('mSkladCategoryData', array('category_id' => $category['id'])); $data->set('category_id', $category['id']); $data->save(); } if (!$data->get('uuid_1c')) { $uuid1c = ''; if ($exchange = $this->modx->getObject('mSkladCategoryExchange', array('category_id' => $category['id']))) { $uuid1c = $exchange->get('uuid_1c'); } if (!$uuid1c) { $uuid = new uuid(); $uuid1c = $uuid->get(); } $data->set('uuid_1c', $uuid1c); $data->save(); } if (!$data->get('uuid')) { if ($exchange = $this->modx->getObject('mSkladCategoryExchange', array('category_id' => $category['id']))) { $data->set('uuid', $exchange->get('uuid')); $data->save(); } } $data->set('active', 1); $data->save(); unset($data); } return true; }
public function process() { if (count($this->products) == 0) { return $this->failure($this->modx->lexicon('msklad_product_err_no_product')); } $stop = 0; if ($this->start == 0) { $this->modx->exec("UPDATE {$this->modx->getTableName('mSkladProductData')} SET active = 0"); } foreach ($this->products as $product) { if (!($data = $this->modx->getObject('mSkladProductData', array('product_id' => $product['id'])))) { $data = $this->modx->newObject('mSkladProductData', array('product_id' => $product['id'])); $data->set('product_id', $product['id']); $data->save(); } if (!$data->get('uuid_1c')) { $uuid1c = ''; if ($exchange = $this->modx->getObject('mSkladProductExchange', array('product_id' => $product['id']))) { $uuid1c = $exchange->get('uuid_1c'); } if (!$uuid1c) { $uuid = new uuid(); $uuid1c = $uuid->get(); } $data->set('uuid_1c', $uuid1c); $data->save(); } if (!$data->get('uuid')) { if ($exchange = $this->modx->getObject('mSkladProductExchange', array('product_id' => $product['id']))) { $data->set('uuid', $exchange->get('uuid')); $data->save(); } } if (!$data->get('price_uuid')) { if ($exchange = $this->modx->getObject('mSkladProductExchange', array('product_id' => $product['id']))) { $data->set('price_uuid', $exchange->get('price_uuid')); $data->save(); } } $data->set('active', 1); $data->save(); unset($data); } if ($this->start + 500 > $this->total) { $stop = 1; } return $this->success(array('total' => $this->total, 'stop' => $stop)); }
/** * @covers Alchemy\Phrasea\Border\File::getUUID */ public function testNewUuid() { $file = __DIR__ . '/../../../../files/temporay.jpg'; if (file_exists($file)) { unlink($file); } copy(__DIR__ . '/../../../../files/p4logo.jpg', $file); $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->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->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->assertEquals($uuid, $newuuid); $this->assertEquals($uuid, $borderFile->getUUID()); if (file_exists($file)) { unlink($file); } }
public static function key() { if (!isset($_SESSION['state_key'])) { $_SESSION['state_key'] = uuid::gen(); } return $_SESSION['state_key']; }
public static function run() { if (!isset($_SERVER['REDIRECT_URL'])) { throw new Exception(); } $_SERVER['REDIRECT_URL'] = substr($_SERVER['REDIRECT_URL'], strlen(config::prefix())); $path = explode('/', $_SERVER['REDIRECT_URL']); //array_shift($path); if ($path && preg_match('/^[0-9a-z]+$/i', $path[0])) { req::$controller = array_shift($path); if ($path && preg_match('/^[0-9a-z]+$/i', $path[0])) { req::$function = array_shift($path); } } unset($path); session::get_instance()->start(); if (uuid::check(req::$controller)) { $obj = state::load(req::$controller); if (!$obj instanceof ctrl) { throw new Exception(); } call_user_func(array($obj, req::$function)); } else { $obj = eval('return new ' . req::$controller . '_ctrl();'); if (!$obj instanceof ctrl) { throw new Exception(); } util::redirect($obj, req::$function, $_GET); } }
static function create($groupname, $description) { $g = new UserGroup(); $g->groupname = $groupname; $g->uuid = uuid::v4(); $g->description = $description; return $g; }
function __construct($structure = null) { $path = expandpath('app:' . $structure); if (file_exists($path) && $structure) { $strx = domdocument::load($path); $domx = new DOMXpath($strx); $cfgs = $domx->query('/configurationschema/config'); foreach ($cfgs as $item) { $key = $item->getAttribute('key'); if ($item->hasAttribute('type')) { $vartype = $item->getAttribute('type'); } else { $vartype = 'string'; } $description = null; $default = null; if ($item->childNodes->length > 0) { foreach ($item->childNodes as $item) { switch ($item->nodeName) { case 'default': $value = $item->getAttribute('value'); $type = $item->getAttribute('type'); if ($type == 'string') { $value = str_replace('${servername}', request::getDomain(), $value); $default = $value; } if ($type == 'integer') { $value = intval($value); $default = $value; } if ($type == 'float') { $value = floatval($value); $default = $value; } if ($type == 'generate') { if ($value == 'uuid') { $default = uuid::v4(); } else { $default = '<unknown>'; } } break; case 'description': $description = $item->nodeValue; break; } } } if (!arr::hasKey($this->data, $key)) { $this->data[$key] = $default; } $this->defs[$key] = array('description' => $description, 'vartype' => $vartype); } $this->flush(); } }
public function createSession($properties = null) { if (!isset($properties)) { $properties = array(); } if (!isset($properties['id'])) { $properties['id'] = uuid::getUniqueID(); } $session = new synch_Session($properties); return $session; }
public function testGet_uuid() { $this->assertTrue(uuid::is_valid(self::$DI['record_1']->get_uuid())); }
public function add($name = '', $id, $idName, $functionName, $sqlFile) { $this->loadConfig($name); $name = ($name === '' ? '' : '_') . $name; Logger::Log('starts ' . $functionName, LogLevel::DEBUG); // decode the received attachment data, as an object $insert = Transaction::decodeTransaction($this->_app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } $name = DBJson::mysql_real_escape_string($name); $id = DBJson::mysql_real_escape_string($id); $uuid = new uuid(); // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { $random = str_replace('-', '', $uuid->get()); $in->setTransactionId(null); // generates the insert data for the object $data = $in->getInsertData(); // starts a query, by using a given file $result = DBRequest::getRoutedSqlFile($this->query, $sqlFile, array('object' => $in, 'name' => $name, $idName => $id, 'random' => $random)); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $queryResult = Query::decodeQuery($result['content']); // sets the new auto-increment id $obj = new Transaction(); $course = Course::ExtractCourse($queryResult[count($queryResult) - 1]->getResponse(), true); $obj->setTransactionId($course->getId() . '_' . $queryResult[count($queryResult) - 2]->getInsertId() . '_' . $random); $res[] = $obj; $this->_app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { Logger::Log($functionName . ' failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->_app->response->setBody(Transaction::encodeTransaction($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Transaction::encodeTransaction($res[0])); } else { $this->_app->response->setBody(Transaction::encodeTransaction($res)); } }
/** * * @param Application $app * @param \collection $collection * * @return \record_adapter */ public static function createStory(Application $app, \collection $collection) { $databox = $collection->get_databox(); $sql = 'INSERT INTO record (coll_id, record_id, parent_record_id, moddate, credate , type, sha256, uuid, originalname, mime) VALUES (:coll_id, null, :parent_record_id, NOW(), NOW() , :type, :sha256, :uuid , :originalname, :mime)'; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute([':coll_id' => $collection->get_coll_id(), ':parent_record_id' => 1, ':type' => 'unknown', ':sha256' => null, ':uuid' => \uuid::generate_v4(), ':originalname' => null, ':mime' => null]); $story_id = $databox->get_connection()->lastInsertId(); $story = new self($app, $databox->get_sbas_id(), $story_id); try { $log_id = $app['phraseanet.logger']($databox)->get_id(); $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment) VALUES (null, :log_id, now(), :record_id, "add", :coll_id,"")'; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute([':log_id' => $log_id, ':record_id' => $story_id, ':coll_id' => $collection->get_coll_id()]); $stmt->closeCursor(); } catch (\Exception $e) { unset($e); } return $story; }
/** * Update a record with a UUID * * @param \databox $databox * @param array $record */ protected function updateRecordUUID(\databox $databox, array $record) { $pathfile = \p4string::addEndSlash($record['path']) . $record['file']; $uuid = \uuid::generate_v4(); try { $media = $this->app['mediavorus']->guess($pathfile); $collection = \collection::get_from_coll_id($app, $databox, (int) $record['coll_id']); $file = new File($this->app, $media, $collection); $uuid = $file->getUUID(true, true); $sha256 = $file->getSha256(); $this->app['monolog']->addInfo(sprintf("Upgrading record %d with uuid %s", $record['record_id'], $uuid)); } catch (\Exception $e) { $this->app['monolog']->addError(sprintf("Uuid upgrade for record %s failed", $record['record_id'])); } $sql = 'UPDATE record SET uuid = :uuid, sha256 = :sha256 WHERE record_id = :record_id'; $params = [':uuid' => $uuid, 'sha256' => $sha256, ':record_id' => $record['record_id']]; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); }
/** * Constructor, must be chained from the worker class using parent::__construct() or * things will fail. * */ public function __construct() { $this->setState(self::STATE_QUEUED); $this->setProgress("Job queued"); $this->_id = uuid::v4(); }
/** * @covers Alchemy\Phrasea\Controller\Admin\Database::emptyDatabase */ public function testPostEmptyBaseWithHighRecordAmount() { $this->setAdmin(true); $base = $this->createDatabox(); $collection = \collection::create(self::$DI['app'], $base, self::$DI['app']['phraseanet.appbox'], 'TESTTODELETE'); self::$createdCollections[] = $collection; $sql = 'INSERT INTO record (coll_id, record_id, parent_record_id, moddate, credate , type, sha256, uuid, originalname, mime) VALUES (:coll_id, null, :parent_record_id, NOW(), NOW() , :type, :sha256, :uuid , :originalname, :mime)'; $stmt = $base->get_connection()->prepare($sql); $i = 0; while ($i < 502) { $stmt->execute([':coll_id' => $collection->get_coll_id(), ':parent_record_id' => 0, ':type' => 'unknown', ':sha256' => null, ':uuid' => \uuid::generate_v4(), ':originalname' => null, ':mime' => null]); $i++; } $stmt->closeCursor(); if ($collection->get_record_amount() < 500) { $this->markTestSkipped('No enough records added'); } $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/'); $json = $this->getJson(self::$DI['client']->getResponse()); $this->assertTrue($json->success); if (count(self::$DI['app']['EM']->getRepository('Phraseanet:Task')->findAll()) === 0) { $this->fail('Task for empty collection has not been created'); } $base->unmount_databox(); $base->delete(); }
public function testIs_null() { $this->assertTrue(uuid::is_null('00000000-0000-0000-0000-000000000000')); }
public function init() { parent::init(); $uuid = new uuid(); $invite = new Zend_Form_Element_Hidden('invite'); $invite->setValue($uuid->get())->setRequired(true)->addValidator(new TA_Form_Validator_Uuid())->setDecorators(array('Composite')); $userModel = new Core_Model_User(); $roles = new Zend_Form_Element_Select('role_id'); $roles->setAttrib('class', 'small')->setLabel('Role')->setOrder(4)->addFilter('Null')->setMultiOptions($userModel->getRolesForSelect('---'))->setDecorators(array('Composite')); $this->addElements(array($roles, $invite)); }
public function save() { if (!$this->uuid) { $this->uuid = uuid::v4(); } if (count($this->modified) > 0) { // Get a database reference $db = new DatabaseConnection(); // Determine what needs to be updated. $mtable = array('user' => false, 'userdata' => false, 'ambient' => false, 'credentials' => false); foreach ($this->modified as $mod) { switch ($mod) { case 'ambient': $mtable['ambient'] = true; break; case 'username': $mtable['user'] = true; break; case 'password': $mtable['credentials'] = true; break; case 'email': $mtable['user'] = true; break; case 'uuid': $mtable['user'] = true; break; case 'active': $mtable['user'] = true; break; case 'displayname': $mtable['userdata'] = true; break; case 'firstname': $mtable['userdata'] = true; break; case 'lastname': $mtable['userdata'] = true; break; case 'sex': $mtable['userdata'] = true; break; case 'country': $mtable['userdata'] = true; break; case 'flags': $mtable['user'] = true; break; case 'userid': break; default: throw new BadArgumentException("Unknown field modified: {$mod}"); } } $this->modified = array(); if (!$this->userid) { // Check to see if the username already exists if (user::find($this->username)) { throw new UserException("User already exists!"); } // Insert $ambient = serialize($this->ambient); $this->userid = $db->insertRow("INSERT INTO " . LEPTON_DB_PREFIX . "users (username,email,uuid,flags,active,registered) VALUES " . "(%s,%s,%s,%s,%d,NOW())", $this->username, $this->email, $this->uuid, $this->flags, $this->active ? 1 : 0); $db->updateRow("INSERT INTO " . LEPTON_DB_PREFIX . "userdata (displayname,firstname,lastname,sex,country,ambient,id) VALUES " . "(%s,%s,%s,%s,%s,%s,%d)", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $ambient, $this->userid); // Update credentials $backend = User::getAuthenticationBackend(); $backend->assignCredentials($this); } else { // Update if ($mtable['ambient'] && $mtable['userdata']) { // Update complete userdata table $ambient = serialize($this->ambient); $db->updateRow("Update " . LEPTON_DB_PREFIX . "userdata SET displayname=%s,firstname=%s,lastname=%s,sex=%s,country=%s,ambient=%s WHERE id=%d", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $ambient, $this->userid); } elseif ($mtable['ambient']) { // Update the ambient column $ambient = serialize($this->ambient); $db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "userdata SET ambient=%s WHERE id=%d ", $ambient, $this->userid); } elseif ($mtable['userdata']) { // Update the userdata columns $db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "userdata SET displayname=%s,firstname=%s,lastname=%s,sex=%s,country=%s WHERE id=%d", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $this->userid); } if ($mtable['user']) { // Update users table $db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "users SET username=%s,email=%s,uuid=%s,flags=%s,active=%s WHERE id=%d", $this->username, $this->email, $this->uuid, $this->flags, $this->active ? 1 : 0, $this->userid); } if ($mtable['credentials']) { // Update credentials $backend = User::getAuthenticationBackend(); $backend->assignCredentials($this); } } } return true; }
/** * Checks for UUID in metadatas * * @todo Check if a file exists with the same checksum * @todo Check if an UUID is contained in the attributes, replace It if * necessary * * @param boolean $generate if true, if no uuid found, a valid one is generated * @param boolean $write if true, writes uuid in all available metadatas * @return File */ public function getUUID($generate = false, $write = false) { if ($this->uuid && !$write) { return $this->uuid; } $availableUUIDs = ['XMP-exif:ImageUniqueID', 'SigmaRaw:ImageUniqueID', 'IPTC:UniqueDocumentID', 'ExifIFD:ImageUniqueID', 'Canon:ImageUniqueID']; if (!$this->uuid) { $metadatas = $this->media->getMetadatas(); $uuid = null; foreach ($availableUUIDs as $meta) { if ($metadatas->containsKey($meta)) { $candidate = $metadatas->get($meta)->getValue()->asString(); if (\uuid::is_valid($candidate)) { $uuid = $candidate; break; } } } if (!$uuid && $generate) { /** * @todo Check if a file exists with the same checksum */ $uuid = \uuid::generate_v4(); } $this->uuid = $uuid; } if ($write) { $value = new MonoValue($this->uuid); $metadatas = new ExiftoolMetadataBag(); foreach ($availableUUIDs as $tagname) { $metadatas->add(new Metadata(TagFactory::getFromRDFTagname($tagname), $value)); } /** * PHPExiftool throws exception on some files not supported */ try { $this->app['exiftool.writer']->reset(); $this->app['exiftool.writer']->write($this->getFile()->getRealPath(), $metadatas); } catch (PHPExiftoolException $e) { } } return $this->uuid; }
protected function evaluateGoodStory($story) { $this->assertArrayHasKey('databox_id', $story); $this->assertTrue(is_int($story['databox_id'])); $this->assertArrayHasKey('story_id', $story); $this->assertTrue(is_int($story['story_id'])); $this->assertArrayHasKey('updated_on', $story); $this->assertDateAtom($story['updated_on']); $this->assertArrayHasKey('created_on', $story); $this->assertDateAtom($story['created_on']); $this->assertArrayHasKey('collection_id', $story); $this->assertTrue(is_int($story['collection_id'])); $this->assertArrayHasKey('thumbnail', $story); $this->assertArrayHasKey('uuid', $story); $this->assertArrayHasKey('@entity@', $story); $this->assertEquals(\API_V1_adapter::OBJECT_TYPE_STORY, $story['@entity@']); $this->assertTrue(\uuid::is_valid($story['uuid'])); if (!is_null($story['thumbnail'])) { $this->assertTrue(is_array($story['thumbnail'])); $this->assertArrayHasKey('player_type', $story['thumbnail']); $this->assertTrue(is_string($story['thumbnail']['player_type'])); $this->assertArrayHasKey('permalink', $story['thumbnail']); $this->assertArrayHasKey('mime_type', $story['thumbnail']); $this->assertTrue(is_string($story['thumbnail']['mime_type'])); $this->assertArrayHasKey('height', $story['thumbnail']); $this->assertTrue(is_int($story['thumbnail']['height'])); $this->assertArrayHasKey('width', $story['thumbnail']); $this->assertTrue(is_int($story['thumbnail']['width'])); $this->assertArrayHasKey('filesize', $story['thumbnail']); $this->assertTrue(is_int($story['thumbnail']['filesize'])); } $this->assertArrayHasKey('records', $story); $this->assertInternalType('array', $story['records']); foreach ($story['metadatas'] as $key => $metadata) { if (null !== $metadata) { $this->assertInternalType('string', $metadata); } if ($key === '@entity@') { continue; } $this->assertEquals(0, strpos($key, 'dc:')); } $this->assertArrayHasKey('@entity@', $story['metadatas']); $this->assertEquals(\API_V1_adapter::OBJECT_TYPE_STORY_METADATA_BAG, $story['metadatas']['@entity@']); foreach ($story['records'] as $record) { $this->evaluateGoodRecord($record); } }
public function __construct(&$set, $value = '') { $this->name = uuid::gen(); $this->value = $value; $this->set =& $set; }
/** * Add a message to the message store. * * @param MailMessage $message The message */ function addMessage(MailMessage $message) { $msgel = $this->mbox->createElement('message'); $message->msgid = uuid::v4(); $msgel->setAttribute('read', $message->read); $msgel->setAttribute('subject', $message->subject); $msgel->setAttribute('msgid', $message->msgid); $msgbody = $this->mbox->createTextNode($message->body); $msgel->appendChild($msgbody); $this->mbox->documentElement->appendChild($msgel); return true; }
public function __construct($value = '') { $this->name = uuid::gen(); $this->value = $value; }
public function preSave() { if ($this->getValue() == '') { $this->setValue(uuid::v4()); } }
/** * * @return Bridge_Api_Youtube */ protected function initialize_transport() { $http_client = new Zend_Gdata_HttpClient(); $http_client->setHeaders('Accept', 'application/atom+xml'); $this->_api = new Zend_Gdata_YouTube($http_client, uuid::generate_v4(), $this->conf->get(['main', 'bridge', 'youtube', 'client_id']), $this->conf->get(['main', 'bridge', 'youtube', 'developer_key'])); $this->_api->setMajorProtocolVersion(2); return $this; }
/** * @description Generate UUID V4 */ function uuid_v4() { $uuid = uuid::v4(); $this->assertEquals(strlen($uuid), uuid::LENGTH); }