security update for uuid xmlsitemap file_field_path
This commit is contained in:
74
sites/all/modules/uuid/.travis.yml
Normal file
74
sites/all/modules/uuid/.travis.yml
Normal file
@@ -0,0 +1,74 @@
|
||||
language: php
|
||||
sudo: false
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
|
||||
mysql:
|
||||
database: drupal
|
||||
username: root
|
||||
encoding: utf8
|
||||
|
||||
install:
|
||||
# add composer's global bin directory to the path
|
||||
# see: https://github.com/drush-ops/drush#install---composer
|
||||
- export PATH="$HOME/.composer/vendor/bin:$PATH"
|
||||
|
||||
# install drush globally
|
||||
- composer global require drush/drush:7.*
|
||||
|
||||
# Install PHP_CodeSniffer and Drupal config
|
||||
- composer global require drupal/coder
|
||||
- phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
|
||||
|
||||
# Create the database
|
||||
- mysql -e 'create database drupal;'
|
||||
|
||||
before_script:
|
||||
|
||||
# Disable sendmail
|
||||
- echo sendmail_path=`which true` >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
||||
|
||||
# Increase the MySQL connection timeout on the PHP end.
|
||||
- echo "mysql.connect_timeout=3000" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
||||
- echo "default_socket_timeout=3000" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
|
||||
|
||||
# Increase the MySQL server timetout and packet size.
|
||||
- mysql -e "SET GLOBAL wait_timeout = 36000;"
|
||||
- mysql -e "SET GLOBAL max_allowed_packet = 33554432;"
|
||||
|
||||
# Download Drupal 7.x
|
||||
- drush pm-download drupal-7 --destination=/tmp --drupal-project-rename=drupal
|
||||
|
||||
# Add our module
|
||||
- ln -s $(pwd) /tmp/drupal/sites/all/modules/
|
||||
|
||||
# Switch to the drupal site directory
|
||||
- cd /tmp/drupal
|
||||
|
||||
# Install site and dependencies
|
||||
- drush -vv --yes site-install --db-url=mysql://root:@127.0.0.1/drupal
|
||||
- drush pm-download entity
|
||||
- drush pm-enable simpletest entity uuid --yes
|
||||
|
||||
# Use the PHP builtin webserver to serve the site.
|
||||
#- drush runserver 8080 > /dev/null 2>&1 &
|
||||
- drush runserver 127.0.0.1:8888 > ~/server.log 2>&1 &
|
||||
- export counter=0; until nc -zv localhost 8888; do if [ $counter -ge 12 ]; then echo "Failed to start server."; exit 1; fi; echo "Waiting for web server to start on port 8888..."; sleep 5; counter=$[$counter +1]; done
|
||||
|
||||
script:
|
||||
- cd /tmp/drupal
|
||||
- php ./scripts/run-tests.sh --verbose --color --php "$(which php)" --url http://127.0.0.1:8888 UUID | tee ~/tests.log
|
||||
- phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme sites/all/modules/uuid
|
||||
|
||||
after_failure:
|
||||
# See what happened with the server.
|
||||
- cat ~/server.log
|
@@ -11,6 +11,7 @@ FEATURES
|
||||
* Automatic UUID generation:
|
||||
UUIDs will be generated for all core entities. An API is provided for other
|
||||
modules to enable support for custom entities.
|
||||
See https://www.drupal.org/node/2387671
|
||||
* UUID API for entities, properties and fields:
|
||||
With this unified API you can load entities with entity_uuid_load() so that
|
||||
all supported properties and fields are made with UUID references. You can
|
||||
|
@@ -6,8 +6,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
* CTools UUID entity context plugin definition.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Entity: UUID"),
|
||||
@@ -17,11 +16,27 @@ $plugin = array(
|
||||
'get children' => 'uuid_entity_uuid_get_children',
|
||||
);
|
||||
|
||||
/**
|
||||
* Fetches the "child" information for a given parent entity.
|
||||
*
|
||||
* @todo document me properly.
|
||||
*
|
||||
* @return array
|
||||
* The children.
|
||||
*/
|
||||
function uuid_entity_uuid_get_child($plugin, $parent, $child) {
|
||||
$plugins = uuid_entity_uuid_get_children($plugin, $parent);
|
||||
return $plugins[$parent . ':' . $child];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches all children types for a given parent entity.
|
||||
*
|
||||
* @todo document me properly.
|
||||
*
|
||||
* @return array
|
||||
* All the children.
|
||||
*/
|
||||
function uuid_entity_uuid_get_children($original_plugin, $parent) {
|
||||
$entities = entity_get_info();
|
||||
$plugins = array();
|
||||
|
@@ -42,7 +42,9 @@ function uuid_devel_load_by_uuid($entity_type, $entity) {
|
||||
// Get the keys for local ID and UUID.
|
||||
$uuid_key = $info['entity keys']['uuid'];
|
||||
$uuid_entities = entity_uuid_load($entity_type, array($entity->{$uuid_key}));
|
||||
// @codingStandardsIgnoreStart
|
||||
return kdevel_print_object(reset($uuid_entities), '$' . $entity_type . '->');
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
else {
|
||||
return t("This entity doesn't support UUID.");
|
||||
|
@@ -5,26 +5,6 @@
|
||||
* Hooks provided by the UUID module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines one or more UUID generators exposed by a module.
|
||||
*
|
||||
* @return
|
||||
* An associative array with the key being the machine name for the
|
||||
* implementation and the values being an array with the following keys:
|
||||
* - title: The human readable name for the generator.
|
||||
* - callback: The function to be called for generating the UUID.
|
||||
*
|
||||
* @see uuid_get_info()
|
||||
*/
|
||||
function hook_uuid_info() {
|
||||
$generators = array();
|
||||
$generators['my_module'] = array(
|
||||
'title' => t('My module UUID generator'),
|
||||
'callback' => 'my_module_generate_uuid',
|
||||
);
|
||||
return $generators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures all records have a UUID assigned to them.
|
||||
*
|
||||
@@ -38,39 +18,35 @@ function hook_uuid_sync() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Let modules transform their properties with local IDs to UUIDs when an
|
||||
* entity is loaded.
|
||||
* Transform entity properties from local IDs to UUIDs when they are loaded.
|
||||
*/
|
||||
function hook_entity_uuid_load(&$entities, $entity_type) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Let modules transform their fields with local IDs to UUIDs when an entity
|
||||
* is loaded.
|
||||
* Transform field values from local IDs to UUIDs when an entity is loaded.
|
||||
*/
|
||||
function hook_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Let modules transform their properties with UUIDs to local IDs when an
|
||||
* entity is saved.
|
||||
* Transform entity properties from UUIDs to local IDs before entity is saved.
|
||||
*/
|
||||
function hook_entity_uuid_presave(&$entity, $entity_type) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Let modules transform their fields with UUIDs to local IDs when an entity
|
||||
* is saved.
|
||||
* Transform field values from UUIDs to local IDs before an entity is saved.
|
||||
*/
|
||||
function hook_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Let modules transform their properties when an entity is saved.
|
||||
* Transform entity properties after an entity is saved.
|
||||
*/
|
||||
function hook_entity_uuid_save($entity, $entity_type) {
|
||||
|
||||
@@ -78,20 +54,24 @@ function hook_entity_uuid_save($entity, $entity_type) {
|
||||
|
||||
/**
|
||||
* Let modules act when an entity is deleted.
|
||||
*
|
||||
* Generally hook_entity_delete() should be used instead of this hook.
|
||||
*
|
||||
* @see hook_entity_delete()
|
||||
*/
|
||||
function hook_entity_uuid_delete($entity, $entity_type) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Let modules modify paths when they are being converted to UUID ones.
|
||||
* Modifies paths when they are being converted to UUID ones.
|
||||
*/
|
||||
function hook_uuid_menu_path_to_uri_alter($path, &$uri) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Let modules modify paths when they are being converted from UUID ones.
|
||||
* Modifies paths when they are being converted from UUID ones.
|
||||
*/
|
||||
function hook_uuid_menu_uri_to_path(&$path, $uri) {
|
||||
|
||||
@@ -121,14 +101,14 @@ function hook_uuid_entities_post_rebuild($plan_name) {
|
||||
/**
|
||||
* Let other modules do things before default entities are created on revert.
|
||||
*/
|
||||
function hook_uuid_entities_pre_rebuild($plan_name) {
|
||||
function hook_uuid_entities_pre_revert($plan_name) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Let other modules do things after default entities are created on revert.
|
||||
*/
|
||||
function hook_uuid_entities_post_rebuild($plan_name) {
|
||||
function hook_uuid_entities_post_revert($plan_name) {
|
||||
|
||||
}
|
||||
|
||||
@@ -152,12 +132,6 @@ function hook_uuid_entities_features_export_field_alter($entity_type, &$entity,
|
||||
function hook_uuid_uri_data($data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter UUID URI data after processing.
|
||||
*/
|
||||
function hook_uuid_uri_data($data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter entity URI before creating UUID URI.
|
||||
*/
|
||||
|
@@ -32,6 +32,31 @@ function node_entity_uuid_presave(&$entity, $entity_type) {
|
||||
if ($entity_type == 'node') {
|
||||
entity_property_uuid_to_id($entity, 'user', array('uid', 'revision_uid'));
|
||||
entity_property_uuid_to_id($entity, 'node', 'tnid');
|
||||
|
||||
// A node always must have an author.
|
||||
if (empty($entity->uid)) {
|
||||
global $user;
|
||||
$entity->uid = $user->uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_uuid_save().
|
||||
*/
|
||||
function node_entity_uuid_save(&$entity, $entity_type) {
|
||||
/*
|
||||
* When a node is translated, the source node's tnid is set to it's own nid.
|
||||
* When deploying the node for the first time the tnid can't be translated
|
||||
* to an nid until after the node has been saved. So if the entity's tnid
|
||||
* is still a uuid at this point it needs to be translated to an nid.
|
||||
*/
|
||||
if ($entity_type == 'node' && uuid_is_valid($entity->tnid)) {
|
||||
entity_property_uuid_to_id($entity, 'node', 'tnid');
|
||||
db_update('node')
|
||||
->fields(array('tnid' => $entity->tnid))
|
||||
->condition('nid', $entity->nid)
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,17 +89,33 @@ function book_entity_uuid_presave(&$entity, $entity_type) {
|
||||
* Implements hook_entity_uuid_presave().
|
||||
*/
|
||||
function user_entity_uuid_presave(&$entity, $entity_type) {
|
||||
if ($entity_type == 'user') {
|
||||
if (!empty($entity->picture)) {
|
||||
$uuids = entity_get_id_by_uuid('file', array($entity->picture['uuid']));
|
||||
$fid = current($uuids);
|
||||
if (!$entity->is_new) {
|
||||
$entity->picture = file_load($fid);
|
||||
}
|
||||
else {
|
||||
$entity->picture = $fid;
|
||||
}
|
||||
}
|
||||
if ($entity_type != 'user') {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to ensure new user's passwords are encrypted. The Services module
|
||||
* transparently encrypts the password for new users. md5() is used by
|
||||
* users who's accounts were migrated from Drupal 6 and who haven't updated
|
||||
* their password.
|
||||
*/
|
||||
if (isset($entity->pass)
|
||||
&& (!('$S$D' == substr($entity->pass, 0, 4)) || preg_match('/^[a-f0-9]{32}$/', $entity->pass))) {
|
||||
// Ensure user's password is hashed.
|
||||
$entity->pass = user_hash_password($entity->pass);
|
||||
}
|
||||
|
||||
if (empty($entity->picture)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uuids = entity_get_id_by_uuid('file', array($entity->picture['uuid']));
|
||||
$fid = current($uuids);
|
||||
if (!$entity->is_new) {
|
||||
$entity->picture = file_load($fid);
|
||||
}
|
||||
else {
|
||||
$entity->picture = $fid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +145,10 @@ function comment_entity_uuid_presave(&$entity, $entity_type) {
|
||||
break;
|
||||
|
||||
case 'comment':
|
||||
// entity_make_entity_local() may have unset cid, add back if necessary.
|
||||
if (!isset($entity->cid)) {
|
||||
$entity->cid = NULL;
|
||||
}
|
||||
entity_property_uuid_to_id($entity, 'user', array('uid', 'u_uid'));
|
||||
entity_property_uuid_to_id($entity, 'node', 'nid');
|
||||
break;
|
||||
@@ -124,11 +169,58 @@ function file_entity_uuid_load(&$entities, $entity_type) {
|
||||
*/
|
||||
function file_entity_uuid_presave(&$entity, $entity_type) {
|
||||
if ($entity_type == 'file') {
|
||||
// entity_make_entity_local() may have unset fid, add back if necessary.
|
||||
if (!isset($entity->fid)) {
|
||||
$entity->fid = NULL;
|
||||
}
|
||||
entity_property_uuid_to_id($entity, 'user', 'uid');
|
||||
if (isset($entity->file_contents)) {
|
||||
$directory = drupal_dirname($entity->uri);
|
||||
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
|
||||
file_unmanaged_save_data(base64_decode($entity->file_contents), $entity->uri, FILE_EXISTS_REPLACE);
|
||||
|
||||
// Write the new file to the local filesystem.
|
||||
if (isset($entity->file_contents) && !empty($entity->filesize)) {
|
||||
// Don't try to write it if it uses a stream wrapper that isn't writeable
|
||||
// (for example, if it is a remotely-hosted video).
|
||||
$scheme = file_uri_scheme($entity->uri);
|
||||
$wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_WRITE);
|
||||
if (empty($wrappers[$scheme])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for an existing file with the same URI.
|
||||
$existing_files = file_load_multiple(array(), array('uri' => $entity->uri));
|
||||
$existing = (object) array('uri' => NULL, 'uuid' => NULL);
|
||||
if (count($existing_files)) {
|
||||
$existing = reset($existing_files);
|
||||
}
|
||||
|
||||
// If this is a new file and there is an existing file with the same URI,
|
||||
// but a different uuid then rename this file.
|
||||
if ($entity->is_new && $entity->uri == $existing->uri && $entity->uuid != $existing->uuid) {
|
||||
$uri = $entity->uri;
|
||||
$replace = FILE_EXISTS_RENAME;
|
||||
}
|
||||
// If this has an id, meaning UUID has already matched the uuid to an
|
||||
// existing file, but it has a URI that matches a file with a different
|
||||
// uuid, then load the file with the matching uuid and use the URI from
|
||||
// that file. The existing file with the matching uuid is most likely a
|
||||
// file that was previously renamed, e.g. as in the condition above, to
|
||||
// avoid conflict. The uuid matches because they are the same file, but
|
||||
// the URI does not because an incrementing number was added as part of
|
||||
// the renaming.
|
||||
elseif ($entity->uri == $existing->uri && $entity->uuid != $existing->uuid) {
|
||||
$file = file_load($entity->fid);
|
||||
$uri = $file->uri;
|
||||
$replace = FILE_EXISTS_REPLACE;
|
||||
}
|
||||
// Otherwise create a new file or replace the existing file contents.
|
||||
else {
|
||||
$uri = $entity->uri;
|
||||
$replace = FILE_EXISTS_REPLACE;
|
||||
}
|
||||
|
||||
$directory = drupal_dirname($uri);
|
||||
if (!empty($directory) && file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
|
||||
$entity->uri = file_unmanaged_save_data(base64_decode($entity->file_contents), $uri, $replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,7 +264,7 @@ function taxonomy_entity_uuid_presave(&$entity, $entity_type) {
|
||||
* Implements hook_entity_uuid_load().
|
||||
*/
|
||||
function field_entity_uuid_load(&$entities, $entity_type) {
|
||||
foreach ($entities as $i => $entity) {
|
||||
foreach ($entities as $entity) {
|
||||
list(, , $bundle_name) = entity_extract_ids($entity_type, $entity);
|
||||
$instances = field_info_instances($entity_type, $bundle_name);
|
||||
|
||||
@@ -269,34 +361,8 @@ function image_field_uuid_presave($entity_type, $entity, $field, $instance, $lan
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_load().
|
||||
*/
|
||||
function node_reference_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
entity_property_id_to_uuid($items, 'node', 'nid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_presave().
|
||||
*/
|
||||
function node_reference_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
entity_property_uuid_to_id($items, 'node', 'nid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_load().
|
||||
*/
|
||||
function user_reference_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
entity_property_id_to_uuid($items, 'user', 'uid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_presave().
|
||||
*/
|
||||
function user_reference_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
entity_property_uuid_to_id($items, 'user', 'uid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_load().
|
||||
*
|
||||
* Kept here because it is in D8 core.
|
||||
*/
|
||||
function entityreference_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
// TODO: This is not really good, but as of now 'entity_property_id_to_uuid()'
|
||||
@@ -306,6 +372,8 @@ function entityreference_field_uuid_load($entity_type, $entity, $field, $instanc
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_presave().
|
||||
*
|
||||
* Kept here because it is in D8 core.
|
||||
*/
|
||||
function entityreference_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
// TODO: This is not really good, but as of now 'entity_property_id_to_uuid()'
|
||||
@@ -313,38 +381,6 @@ function entityreference_field_uuid_presave($entity_type, $entity, $field, $inst
|
||||
entity_property_uuid_to_id($items, $field['settings']['target_type'], 'target_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_uuid_load().
|
||||
*/
|
||||
function field_collection_entity_uuid_load(&$entities, $entity_type) {
|
||||
if ($entity_type == 'field_collection_item') {
|
||||
entity_property_id_to_uuid($entities, 'field_collection_item', 'value');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_uuid_presave().
|
||||
*/
|
||||
function field_collection_entity_uuid_presave(&$entity, $entity_type) {
|
||||
if ($entity_type == 'field_collection_item') {
|
||||
entity_property_uuid_to_id($entity, 'field_collection_item', 'value');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_load().
|
||||
*/
|
||||
function field_collection_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
entity_property_id_to_uuid($items, 'field_collection_item', 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_uuid_presave().
|
||||
*/
|
||||
function field_collection_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
entity_property_uuid_to_id($items, 'field_collection_item', 'value');
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "Field implementations"
|
||||
*/
|
||||
@@ -358,24 +394,35 @@ function field_collection_field_uuid_presave($entity_type, $entity, $field, $ins
|
||||
* Implements hook_uuid_entities_features_export_entity_alter().
|
||||
*/
|
||||
function node_uuid_entities_features_export_entity_alter(&$entity, $entity_type) {
|
||||
if ($entity_type == 'node') {
|
||||
foreach (array('data', 'name', 'picture', 'revision_uid', 'last_comment_timestamp') as $property) {
|
||||
if (property_exists($entity, $property)) {
|
||||
unset($entity->{$property});
|
||||
}
|
||||
if ('node' != $entity_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'data',
|
||||
'name',
|
||||
'picture',
|
||||
'revision_uid',
|
||||
'last_comment_timestamp',
|
||||
);
|
||||
foreach ($properties as $property) {
|
||||
if (property_exists($entity, $property)) {
|
||||
unset($entity->{$property});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uuid_entities_features_export_entity_alter().
|
||||
* Implements hook_uuid_entities_features_export_entity_alter().
|
||||
*/
|
||||
function user_uuid_entities_features_export_entity_alter(&$entity, $entity_type) {
|
||||
if ($entity_type == 'user') {
|
||||
foreach (array('data', 'access', 'login') as $property) {
|
||||
if (property_exists($entity, $property)) {
|
||||
unset($entity->{$property});
|
||||
}
|
||||
if ('user' != $entity_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (array('data', 'access', 'login') as $property) {
|
||||
if (property_exists($entity, $property)) {
|
||||
unset($entity->{$property});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,17 +438,6 @@ function file_uuid_entities_features_export_field_alter($entity_type, $entity, $
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_entities_features_export_entity_alter().
|
||||
*/
|
||||
function workbench_uuid_entities_features_export_entity_alter(&$entity, $entity_type) {
|
||||
foreach (array('workbench_moderation', 'my_revision', 'workbench_access', 'workbench_access_scheme', 'workbench_access_by_role') as $property) {
|
||||
if (isset($entity->{$property})) {
|
||||
unset($entity->{$property});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "Export alterations"
|
||||
*/
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementats hook_drush_command().
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function uuid_drush_command() {
|
||||
$items = array();
|
||||
@@ -18,7 +18,7 @@ function uuid_drush_command() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementats of hook_drush_help().
|
||||
* Implements hook_drush_help().
|
||||
*/
|
||||
function uuid_drush_help($section) {
|
||||
switch ($section) {
|
||||
|
@@ -11,8 +11,7 @@
|
||||
class UuidEntityException extends Exception {}
|
||||
|
||||
/**
|
||||
* Helper function that returns entity info for all supported core modules,
|
||||
* relevant for UUID functionality.
|
||||
* Returns entity info for all supported core entities.
|
||||
*
|
||||
* @see uuid_entity_info()
|
||||
* @see uuid_schema_alter()
|
||||
@@ -76,9 +75,9 @@ function uuid_get_core_entity_info() {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements of hook_entity_info_alter().
|
||||
* Implements hook_entity_info_alter().
|
||||
*
|
||||
* @see uuid_core_entity_info().
|
||||
* @see uuid_core_entity_info()
|
||||
*/
|
||||
function uuid_entity_info_alter(&$info) {
|
||||
foreach (uuid_get_core_entity_info() as $entity_type => $core_info) {
|
||||
@@ -91,21 +90,24 @@ function uuid_entity_info_alter(&$info) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_entity_property_info_alter().
|
||||
* Implements hook_entity_property_info_alter().
|
||||
*
|
||||
* This adds the UUID as an entity property for all UUID-enabled entities
|
||||
* which automatically gives us token and Rules integration.
|
||||
*/
|
||||
function uuid_entity_property_info_alter(&$info) {
|
||||
foreach (entity_get_info() as $entity_type => $entity_info) {
|
||||
if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE && !empty($entity_info['entity keys']['uuid'])) {
|
||||
if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE
|
||||
&& !empty($entity_info['entity keys']['uuid'])
|
||||
&& empty($info[$entity_type]['properties'][$entity_info['entity keys']['uuid']])) {
|
||||
$info[$entity_type]['properties'][$entity_info['entity keys']['uuid']] = array(
|
||||
'label' => t('UUID'),
|
||||
'type' => 'text',
|
||||
'description' => t('The universally unique ID.'),
|
||||
'schema field' => $entity_info['entity keys']['uuid'],
|
||||
);
|
||||
if (!empty($entity_info['entity keys']['revision uuid'])) {
|
||||
if (!empty($entity_info['entity keys']['revision uuid'])
|
||||
&& empty($info[$entity_type]['properties'][$entity_info['entity keys']['revision uuid']])) {
|
||||
$info[$entity_type]['properties'][$entity_info['entity keys']['revision uuid']] = array(
|
||||
'label' => t('Revision UUID'),
|
||||
'type' => 'text',
|
||||
@@ -118,7 +120,7 @@ function uuid_entity_property_info_alter(&$info) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_entity_presave().
|
||||
* Implements hook_entity_presave().
|
||||
*
|
||||
* This is where all UUID-enabled entities get their UUIDs.
|
||||
*/
|
||||
@@ -131,7 +133,19 @@ function uuid_entity_presave($entity, $entity_type) {
|
||||
}
|
||||
if (!empty($info['entity keys']['revision uuid'])) {
|
||||
$vuuid_key = $info['entity keys']['revision uuid'];
|
||||
if ((isset($entity->revision) && $entity->revision == TRUE) || empty($entity->{$vuuid_key})) {
|
||||
// If this entity comes from a remote environment and have a revision UUID
|
||||
// that exists locally we should not create a new revision. Because
|
||||
// otherwise revisions won't be tracked universally.
|
||||
// TODO: Move code dependent on the uuid_services module into it's own
|
||||
// implementation of hook_entity_presave().
|
||||
if (!empty($entity->uuid_services) && isset($entity->{$vuuid_key})) {
|
||||
$vuuid_exists = (bool) entity_get_id_by_uuid($entity_type, array($entity->{$vuuid_key}), TRUE);
|
||||
if ($vuuid_exists) {
|
||||
$entity->revision = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ((isset($entity->revision) && $entity->revision == TRUE && empty($entity->uuid_services)) || empty($entity->{$vuuid_key})) {
|
||||
$entity->{$vuuid_key} = uuid_generate();
|
||||
}
|
||||
}
|
||||
@@ -151,12 +165,26 @@ function uuid_entity_presave($entity, $entity_type) {
|
||||
/**
|
||||
* Load entities by their UUID, that only should containing UUID references.
|
||||
*
|
||||
* Optionally load revisions by their VUUID by passing it into $conditions.
|
||||
* Ex. $conditions['vuuid'][$vuuid]
|
||||
*
|
||||
* This function is mostly useful if you want to load an entity from the local
|
||||
* database that only should contain UUID references.
|
||||
*
|
||||
* @see entity_load()
|
||||
*/
|
||||
function entity_uuid_load($entity_type, $uuids = array(), $conditions = array(), $reset = FALSE) {
|
||||
// Allow Revision UUID to be passed in $conditions and translate.
|
||||
$entity_info[$entity_type] = entity_get_info($entity_type);
|
||||
$revision_key = $entity_info[$entity_type]['entity keys']['revision'];
|
||||
if (isset($entity_info[$entity_type]['entity keys']['revision uuid'])) {
|
||||
$revision_uuid_key = $entity_info[$entity_type]['entity keys']['revision uuid'];
|
||||
}
|
||||
if (isset($revision_uuid_key) && isset($conditions[$revision_uuid_key])) {
|
||||
$revision_id = entity_get_id_by_uuid($entity_type, array($conditions[$revision_uuid_key]), TRUE);
|
||||
$conditions[$revision_key] = $revision_id[$conditions[$revision_uuid_key]];
|
||||
unset($conditions[$revision_uuid_key]);
|
||||
}
|
||||
$ids = entity_get_id_by_uuid($entity_type, $uuids);
|
||||
$results = entity_load($entity_type, $ids, $conditions, $reset);
|
||||
$entities = array();
|
||||
@@ -209,10 +237,27 @@ function entity_uuid_save($entity_type, $entity) {
|
||||
throw new UuidEntityException(t('Calling %function requires the Entity API module (!link).', array('%function' => __FUNCTION__, '!link' => 'http://drupal.org/project/entity')));
|
||||
}
|
||||
|
||||
$info = entity_get_info($entity_type);
|
||||
$uuid_key = $info['entity keys']['uuid'];
|
||||
if (empty($entity->{$uuid_key}) || !uuid_is_valid($entity->{$uuid_key})) {
|
||||
watchdog('Entity UUID', 'Attempted to save an entity with an invalid UUID', array(), WATCHDOG_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Falling back on the variable node_options_[type] is not something an API
|
||||
// function should take care of. With normal (non UUID) nodes this is dealt
|
||||
// with in the form submit handler, i.e. not in node_save().
|
||||
// But since using entity_uuid_save() usually means you're trying to manage
|
||||
// entities remotely we do respect this variable here to make it work as the
|
||||
// node form, but only if we explicitly haven't set $node->revision already.
|
||||
if ($entity_type == 'node' && !isset($entity->revision) && in_array('revision', variable_get('node_options_' . $entity->type, array()))) {
|
||||
$entity->revision = 1;
|
||||
}
|
||||
|
||||
entity_make_entity_local($entity_type, $entity);
|
||||
|
||||
// Save the entity.
|
||||
entity_save($entity_type, $entity);
|
||||
$result = entity_save($entity_type, $entity);
|
||||
|
||||
$hook = 'entity_uuid_save';
|
||||
foreach (module_implements($hook) as $module) {
|
||||
@@ -221,6 +266,7 @@ function entity_uuid_save($entity_type, $entity) {
|
||||
$function($entity, $entity_type);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,6 +305,10 @@ function entity_make_entity_local($entity_type, $entity) {
|
||||
$vid = NULL;
|
||||
// Fetch the local revision ID by its UUID.
|
||||
if (isset($entity->{$vuuid_key})) {
|
||||
// It's important to note that the revision UUID might be set here but
|
||||
// there might not exist a correspondant local revision ID in which case
|
||||
// we should unset the assigned revision ID to not confuse anyone with
|
||||
// revision IDs that might come from other environments.
|
||||
$vids = entity_get_id_by_uuid($entity_type, array($entity->{$vuuid_key}), TRUE);
|
||||
$vid = reset($vids);
|
||||
}
|
||||
@@ -268,9 +318,10 @@ function entity_make_entity_local($entity_type, $entity) {
|
||||
elseif (!empty($vid)) {
|
||||
$entity->{$vid_key} = $vid;
|
||||
}
|
||||
// Nodes need this when trying to save an existing node without a vid.
|
||||
// If the revision ID was unset before this (or just missing for some
|
||||
// reason) we fetch the current revision ID to build a better
|
||||
// representation of the node object we're working with.
|
||||
if ($entity_type == 'node' && !isset($entity->vid) && !$entity->is_new) {
|
||||
$entity->revision = 0;
|
||||
$entity->vid = db_select('node', 'n')
|
||||
->condition('n.nid', $entity->nid)
|
||||
->fields('n', array('vid'))
|
||||
@@ -289,7 +340,7 @@ function entity_make_entity_local($entity_type, $entity) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new UuidEntityException(t('Trying to operate on a @type entity, which doesn\'t support UUIDs.', array('@type' => $info['label'])));
|
||||
throw new UuidEntityException(t("Trying to operate on a @type entity, which doesn\'t support UUIDs.", array('@type' => $info['label'])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,6 +363,7 @@ function entity_uuid_delete($entity_type, $uuid) {
|
||||
// Fetch the local ID by its UUID.
|
||||
$ids = entity_get_id_by_uuid($entity_type, array($uuid));
|
||||
$id = reset($ids);
|
||||
$entity = entity_load($entity_type, array($id));
|
||||
|
||||
// Let other modules transform UUID references to local ID references.
|
||||
$hook = 'entity_uuid_delete';
|
||||
@@ -322,11 +374,14 @@ function entity_uuid_delete($entity_type, $uuid) {
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($entity)) {
|
||||
return FALSE;
|
||||
}
|
||||
// Delete the entity.
|
||||
return entity_delete($entity_type, $id);
|
||||
}
|
||||
else {
|
||||
throw new UuidEntityException(t('Trying to delete a @type entity, which doesn\'t support UUIDs.', array('@type' => $info['label'])));
|
||||
throw new UuidEntityException(t("Trying to delete a @type entity, which doesn\'t support UUIDs.", array('@type' => $info['label'])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,24 +389,34 @@ function entity_uuid_delete($entity_type, $uuid) {
|
||||
* Helper function that retrieves entity IDs by their UUIDs.
|
||||
*
|
||||
* @todo
|
||||
* Statically cache as many IDs as possible and limit the query.
|
||||
* Limit the query.
|
||||
*
|
||||
* @param $entity_type
|
||||
* @param string $entity_type
|
||||
* The entity type we should be dealing with.
|
||||
* @param $uuids
|
||||
* An array of UUIDs for which we should find their entity IDs. If $revision
|
||||
* @param array $uuids
|
||||
* List of UUIDs for which we should find their entity IDs. If $revision
|
||||
* is TRUE this should be revision UUIDs instead.
|
||||
* @param $revision
|
||||
* @param bool $revision
|
||||
* If TRUE the revision IDs is returned instead.
|
||||
* @return
|
||||
* Array of entity IDs keyed by their UUIDs. If $revision is TRUE revision
|
||||
*
|
||||
* @return array
|
||||
* List of entity IDs keyed by their UUIDs. If $revision is TRUE revision
|
||||
* IDs and UUIDs are returned instead.
|
||||
*/
|
||||
function entity_get_id_by_uuid($entity_type, $uuids, $revision = FALSE) {
|
||||
if (empty($uuids)) {
|
||||
return array();
|
||||
}
|
||||
$cached_ids = entity_uuid_id_cache($entity_type, $uuids, $revision);
|
||||
if (count($cached_ids) == count($uuids)) {
|
||||
return $cached_ids;
|
||||
}
|
||||
$uuids = array_diff($uuids, $cached_ids);
|
||||
$info = entity_get_info($entity_type);
|
||||
// Some contrib entities has no support for UUID, let's skip them.
|
||||
if (empty($info['uuid'])) {
|
||||
return array();
|
||||
}
|
||||
// Find out what entity keys to use.
|
||||
if (!$revision) {
|
||||
$table = $info['base table'];
|
||||
@@ -369,35 +434,61 @@ function entity_get_id_by_uuid($entity_type, $uuids, $revision = FALSE) {
|
||||
}
|
||||
|
||||
// Get all UUIDs in one query.
|
||||
return db_select($table, 't')
|
||||
$result = db_select($table, 't')
|
||||
->fields('t', array($uuid_key, $id_key))
|
||||
->condition($uuid_key, array_values($uuids), 'IN')
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
$cache = &drupal_static('entity_uuid_id_cache', array());
|
||||
$cache[$entity_type][(int) $revision] += $result;
|
||||
return $result + $cached_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper caching function.
|
||||
*/
|
||||
function entity_uuid_id_cache($entity_type, $ids, $revision) {
|
||||
$cache = &drupal_static(__FUNCTION__, array());
|
||||
if (empty($cache[$entity_type][(int) $revision])) {
|
||||
$cache[$entity_type][(int) $revision] = array();
|
||||
}
|
||||
$cached_ids = $cache[$entity_type][(int) $revision];
|
||||
return array_intersect_key($cached_ids, array_flip($ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that retrieves UUIDs by their entity IDs.
|
||||
*
|
||||
* @todo
|
||||
* Statically cache as many IDs as possible and limit the query.
|
||||
* Limit the query.
|
||||
*
|
||||
* @param $entity_type
|
||||
* @param string $entity_type
|
||||
* The entity type we should be dealing with.
|
||||
* @param $ids
|
||||
* An array of entity IDs for which we should find their UUIDs. If $revision
|
||||
* @param array $ids
|
||||
* List of entity IDs for which we should find their UUIDs. If $revision
|
||||
* is TRUE this should be revision IDs instead.
|
||||
* @param $revision
|
||||
* @param bool $revision
|
||||
* If TRUE the revision UUIDs is returned instead.
|
||||
* @return
|
||||
* Array of entity UUIDs keyed by their IDs. If $revision is TRUE revision
|
||||
*
|
||||
* @return array
|
||||
* List of entity UUIDs keyed by their IDs. If $revision is TRUE revision
|
||||
* IDs and UUIDs are returned instead.
|
||||
*/
|
||||
function entity_get_uuid_by_id($entity_type, $ids, $revision = FALSE) {
|
||||
if (empty($ids)) {
|
||||
return array();
|
||||
}
|
||||
$cached_ids = array_flip(entity_uuid_id_cache($entity_type, $ids, $revision));
|
||||
if (count($cached_ids) == count($ids)) {
|
||||
return $cached_ids;
|
||||
}
|
||||
$ids = array_diff($ids, $cached_ids);
|
||||
|
||||
$info = entity_get_info($entity_type);
|
||||
// Some contrib entities has no support for UUID, let's skip them.
|
||||
if (empty($info['uuid'])) {
|
||||
return array();
|
||||
}
|
||||
// Find out what entity keys to use.
|
||||
if (!$revision) {
|
||||
$table = $info['base table'];
|
||||
@@ -415,11 +506,14 @@ function entity_get_uuid_by_id($entity_type, $ids, $revision = FALSE) {
|
||||
}
|
||||
|
||||
// Get all UUIDs in one query.
|
||||
return db_select($table, 't')
|
||||
$result = db_select($table, 't')
|
||||
->fields('t', array($id_key, $uuid_key))
|
||||
->condition($id_key, array_values($ids), 'IN')
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
$cache = &drupal_static('entity_uuid_id_cache', array());
|
||||
$cache[$entity_type][(int) $revision] += array_flip($result);
|
||||
return $result + $cached_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,12 +526,12 @@ function entity_get_uuid_by_id($entity_type, $ids, $revision = FALSE) {
|
||||
* @todo
|
||||
* Add tests for this function.
|
||||
*
|
||||
* @param $objects
|
||||
* An array of objects that should get $properties changed. Can be either an
|
||||
* @param array $objects
|
||||
* List of objects that should get $properties changed. Can be either an
|
||||
* entity object or a field items array.
|
||||
* @param $entity_type
|
||||
* @param string $entity_type
|
||||
* The type of entity that all $properties refers to.
|
||||
* @param $properties
|
||||
* @param array $properties
|
||||
* An array of properties that should be changed. All properties must refer to
|
||||
* the same type of entity (the one referenced in $entity_type).
|
||||
*/
|
||||
@@ -488,12 +582,12 @@ function entity_property_id_to_uuid(&$objects, $entity_type, $properties) {
|
||||
* @todo
|
||||
* Add tests for this function.
|
||||
*
|
||||
* @param $objects
|
||||
* An array of objects that should get $properties changed. Can be either an
|
||||
* @param array $objects
|
||||
* List of objects that should get $properties changed. Can be either an
|
||||
* entity object or a field items array.
|
||||
* @param $entity_type
|
||||
* @param string $entity_type
|
||||
* The type of entity that all $properties refers to.
|
||||
* @param $properties
|
||||
* @param array $properties
|
||||
* An array of properties that should be changed. All properties must refer to
|
||||
* the same type of entity (the one referenced in $entity_type).
|
||||
*/
|
||||
|
@@ -84,7 +84,15 @@ function uuid_entities_features_export_render($module_name, $components, $export
|
||||
}
|
||||
// We unset some common timestamp properties, since those will change and
|
||||
// constantly leave the feature overidden.
|
||||
$keys = array('created', 'updated', 'changed', 'revision_timestamp', 'timestamp', 'stamp', 'current');
|
||||
$keys = array(
|
||||
'created',
|
||||
'updated',
|
||||
'changed',
|
||||
'revision_timestamp',
|
||||
'timestamp',
|
||||
'stamp',
|
||||
'current',
|
||||
);
|
||||
foreach ($keys as $key) {
|
||||
if (isset($entity->{$key})) {
|
||||
unset($entity->{$key});
|
||||
@@ -93,7 +101,7 @@ function uuid_entities_features_export_render($module_name, $components, $export
|
||||
// Let other modules alter exported entities.
|
||||
drupal_alter('uuid_entities_features_export_entity', $entity, $entity_type);
|
||||
// Field handling.
|
||||
list(,, $bundle_name) = entity_extract_ids($entity_type, $entity);
|
||||
list(, , $bundle_name) = entity_extract_ids($entity_type, $entity);
|
||||
$instances = field_info_instances($entity_type, $bundle_name);
|
||||
foreach ($instances as $field_name => $instance) {
|
||||
$field = field_info_field($field_name);
|
||||
@@ -121,7 +129,10 @@ function uuid_entities_features_export_render($module_name, $components, $export
|
||||
}
|
||||
uuid_entities_features_clean($entity);
|
||||
|
||||
// Convert entities to array to avoid having them in JSON, returned from standard implementation of $entity->export().
|
||||
/*
|
||||
* Convert entities to array to avoid having them in JSON, returned
|
||||
* from standard implementation of $entity->export().
|
||||
*/
|
||||
if (is_object($entity) && method_exists($entity, 'export')) {
|
||||
$entity = get_object_vars($entity);
|
||||
}
|
||||
@@ -134,14 +145,14 @@ function uuid_entities_features_export_render($module_name, $components, $export
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements [component]_features_export_rebuild().
|
||||
* Implements [component]_features_rebuild().
|
||||
*/
|
||||
function uuid_entities_features_rebuild($module_name) {
|
||||
uuid_entities_rebuild($module_name, 'rebuild');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements [component]_features_export_revert().
|
||||
* Implements [component]_features_revert().
|
||||
*/
|
||||
function uuid_entities_features_revert($module_name) {
|
||||
uuid_entities_rebuild($module_name, 'revert');
|
||||
@@ -157,6 +168,7 @@ function uuid_entities_rebuild($module_name = '', $op = 'rebuild') {
|
||||
foreach ($entities as $plan_name => $entities) {
|
||||
// Let other modules do things before default entities are created.
|
||||
module_invoke_all("uuid_entities_pre_$op", $plan_name);
|
||||
drupal_alter("uuid_entities_pre_$op", $entities, $plan_name);
|
||||
foreach ($entities as $entity) {
|
||||
entity_uuid_save($entity->__metadata['type'], $entity);
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/**
|
||||
* Pattern for detecting a valid UUID.
|
||||
*/
|
||||
define('UUID_PATTERN', '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}');
|
||||
define('UUID_PATTERN', '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}');
|
||||
|
||||
/**
|
||||
* Generates an universally unique identifier.
|
||||
@@ -17,7 +17,7 @@ define('UUID_PATTERN', '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}');
|
||||
* universally unique identifiers. If that doesn't exist, then it falls back on
|
||||
* PHP for generating that.
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* An UUID, made up of 32 hex digits and 4 hyphens.
|
||||
*/
|
||||
function uuid_generate() {
|
||||
@@ -37,6 +37,61 @@ function uuid_generate() {
|
||||
return $callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a version 5 compliant UUID.
|
||||
*
|
||||
* @param string $namespace
|
||||
* Namespace UUID as a hex encoded string.
|
||||
* @param string $name
|
||||
* The name for the generating the UUID.
|
||||
*
|
||||
* @return string
|
||||
* UUID as a hex encoded string.
|
||||
*
|
||||
* @link http://www.php.net/manual/en/function.uniqid.php#94959 Code lifted from
|
||||
* PHP manual comment by Andrew Moore. @endlink
|
||||
*/
|
||||
function uuid_generate_v5($namespace, $name) {
|
||||
if (!uuid_is_valid($namespace)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get hexadecimal components of namespace.
|
||||
$nhex = str_replace(array('-', '{', '}'), '', $namespace);
|
||||
|
||||
// Binary Value.
|
||||
$nstr = '';
|
||||
|
||||
// Convert Namespace UUID to bits.
|
||||
for ($i = 0; $i < strlen($nhex); $i += 2) {
|
||||
$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
|
||||
}
|
||||
|
||||
// Calculate hash value.
|
||||
$hash = sha1($nstr . $name);
|
||||
|
||||
return sprintf('%08s-%04s-%04x-%04x-%12s',
|
||||
|
||||
// 32 bits for "time_low".
|
||||
substr($hash, 0, 8),
|
||||
|
||||
// 16 bits for "time_mid".
|
||||
substr($hash, 8, 4),
|
||||
|
||||
// 16 bits for "time_hi_and_version",
|
||||
// four most significant bits holds version number 5.
|
||||
(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
|
||||
|
||||
// 16 bits, 8 bits for "clk_seq_hi_res",
|
||||
// 8 bits for "clk_seq_low",
|
||||
// two most significant bits holds zero and one for variant DCE1.1.
|
||||
(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
|
||||
|
||||
// 48 bits for "node".
|
||||
substr($hash, 20, 12)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate all missing UUIDs.
|
||||
*/
|
||||
@@ -53,7 +108,7 @@ function uuid_sync_all() {
|
||||
* The type of entity being used.
|
||||
*
|
||||
* @return string
|
||||
* The generated UUID URI or normal URI if entity doesn't support UUIDs.
|
||||
* The generated UUID URI or normal URI if entity doesn't support UUIDs.
|
||||
*/
|
||||
function uuid_entity_uuid_uri($entity, $entity_type) {
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
@@ -73,13 +128,13 @@ function uuid_entity_uuid_uri($entity, $entity_type) {
|
||||
/**
|
||||
* Converts an ID URI string to an entity data array.
|
||||
*
|
||||
* @see uuid_id_uri_array_to_data()
|
||||
*
|
||||
* @param string $uri
|
||||
* The URI to convert.
|
||||
* The URI to convert.
|
||||
*
|
||||
* @return array
|
||||
* The entity data.
|
||||
* The entity data.
|
||||
*
|
||||
* @see uuid_id_uri_array_to_data()
|
||||
*/
|
||||
function uuid_id_uri_to_data($uri) {
|
||||
$parts = explode('/', $uri);
|
||||
@@ -90,10 +145,10 @@ function uuid_id_uri_to_data($uri) {
|
||||
* Converts a URI array to entity data array.
|
||||
*
|
||||
* @param array $uri
|
||||
* The URI parts, often taken from arg().
|
||||
* The URI parts, often taken from arg().
|
||||
*
|
||||
* @return array
|
||||
* The entity data.
|
||||
* The entity data.
|
||||
*/
|
||||
function uuid_id_uri_array_to_data($uri) {
|
||||
$data = array(
|
||||
@@ -110,13 +165,13 @@ function uuid_id_uri_array_to_data($uri) {
|
||||
/**
|
||||
* Converts a UUID URI string to an entity data array.
|
||||
*
|
||||
* @see uuid_uri_array_to_data()
|
||||
*
|
||||
* @param string $uri
|
||||
* The URI to convert.
|
||||
* The URI to convert.
|
||||
*
|
||||
* @return array
|
||||
* The entity data.
|
||||
* The entity data.
|
||||
*
|
||||
* @see uuid_uri_array_to_data()
|
||||
*/
|
||||
function uuid_uri_to_data($uri, $strip_uuid = TRUE) {
|
||||
return uuid_uri_array_to_data(explode('/', $uri));
|
||||
@@ -126,10 +181,10 @@ function uuid_uri_to_data($uri, $strip_uuid = TRUE) {
|
||||
* Converts a URI array to entity data array.
|
||||
*
|
||||
* @param array $uri
|
||||
* The URI parts, often taken from arg().
|
||||
* The URI parts, often taken from arg().
|
||||
*
|
||||
* @return array
|
||||
* The entity data.
|
||||
* The entity data.
|
||||
*/
|
||||
function uuid_uri_array_to_data($uri, $strip_uuid = TRUE) {
|
||||
if ($strip_uuid) {
|
||||
@@ -138,8 +193,8 @@ function uuid_uri_array_to_data($uri, $strip_uuid = TRUE) {
|
||||
|
||||
$data = array(
|
||||
'request' => $uri,
|
||||
'entity_type' => $uri[0],
|
||||
'uuid' => $uri[1],
|
||||
'entity_type' => isset($uri[0]) ? $uri[0] : NULL,
|
||||
'uuid' => isset($uri[1]) ? $uri[1] : NULL,
|
||||
);
|
||||
|
||||
drupal_alter('uuid_uri_data', $data);
|
||||
@@ -165,40 +220,56 @@ function _uuid_generate_pecl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a UUID v4 using PHP code.
|
||||
*
|
||||
* Based on code from @see http://php.net/uniqid#65879 , but corrected.
|
||||
* Generates a UUID v4 (RFC 4122 section 4.4) using PHP code.
|
||||
*
|
||||
* @see http://www.rfc-editor.org/rfc/rfc4122.txt
|
||||
*
|
||||
* The UUID layout and fields are defined in section 4.1.2.
|
||||
*
|
||||
* Note that there are inconsistencies in the RFC with respect to
|
||||
* bit numbering. Network Order is correct, so the most significant bit
|
||||
* always appears first (in left-to-right sequence). See errata 3546:
|
||||
* http://www.rfc-editor.org/errata_search.php?rfc=4122&eid=3546
|
||||
*
|
||||
* Based on code from http://php.net/uniqid
|
||||
*/
|
||||
function _uuid_generate_php() {
|
||||
// The field names refer to RFC 4122 section 4.1.2.
|
||||
// We limit each generated number to 16 bits (maximum value 0xffff)
|
||||
// because mt_rand() returns a *signed* integer, and hence a 32-bit
|
||||
// value can only have a 31-bit magnitude. Constructing a 32-bit
|
||||
// number from two 16-bit random numbers guarantees that all 32 bits
|
||||
// are random.
|
||||
return sprintf('%04x%04x-%04x-4%03x-%04x-%04x%04x%04x',
|
||||
// 32 bits for "time_low".
|
||||
mt_rand(0, 65535), mt_rand(0, 65535),
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
// 16 bits for "time_mid".
|
||||
mt_rand(0, 65535),
|
||||
// 12 bits after the 0100 of (version) 4 for "time_hi_and_version".
|
||||
mt_rand(0, 4095),
|
||||
bindec(substr_replace(sprintf('%016b', mt_rand(0, 65535)), '10', 0, 2)),
|
||||
// 8 bits, the last two of which (positions 6 and 7) are 01, for "clk_seq_hi_res"
|
||||
// (hence, the 2nd hex digit after the 3rd hyphen can only be 1, 5, 9 or d)
|
||||
// 8 bits for "clk_seq_low" 48 bits for "node".
|
||||
mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)
|
||||
mt_rand(0, 0xffff),
|
||||
// 12 bits after the initial 0100 (version 4) for "time_hi_and_version".
|
||||
mt_rand(0, 0x0fff),
|
||||
// 16 bits in total for "clk_seq_hi_res" and "clk_seq_low", with the
|
||||
// most significant 2 bits of clk_seq_hi_res set to '10'. We do a
|
||||
// bitwise OR of a random 14-bit value (maximum 0x3fff) with 0x8000
|
||||
// (a 16-bit integer with only the most significant bit set).
|
||||
mt_rand(0, 0x3fff) | 0x8000,
|
||||
// 48 bits for "node".
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// This is wrapped in an if block to avoid conflicts with PECL's uuid_is_valid().
|
||||
/**
|
||||
* Check that a string appears to be in the format of a UUID.
|
||||
*
|
||||
* @param $uuid
|
||||
* The string to test.
|
||||
*
|
||||
* @return
|
||||
* TRUE if the string is well formed.
|
||||
*/
|
||||
// The if block avoids conflicts with PECL's uuid_is_valid().
|
||||
if (!function_exists('uuid_is_valid')) {
|
||||
|
||||
/**
|
||||
* Check that a string appears to be in the format of a UUID.
|
||||
*
|
||||
* @param string $uuid
|
||||
* The string to test.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the string is well formed.
|
||||
*/
|
||||
function uuid_is_valid($uuid) {
|
||||
return preg_match('/^' . UUID_PATTERN . '$/', $uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,10 +4,11 @@ core = 7.x
|
||||
package = UUID
|
||||
configure = admin/config/system/uuid
|
||||
files[] = uuid.test
|
||||
dependencies[] = node
|
||||
dependencies[] = user
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-03
|
||||
version = "7.x-1.0-alpha3+52-dev"
|
||||
; Information added by Drupal.org packaging script on 2018-07-19
|
||||
version = "7.x-1.2"
|
||||
core = "7.x"
|
||||
project = "uuid"
|
||||
datestamp = "1359858369"
|
||||
|
||||
datestamp = "1531990689"
|
||||
|
@@ -29,14 +29,28 @@ function uuid_schema_field_definition() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_schema_alter().
|
||||
* Implements hook_schema_alter().
|
||||
*/
|
||||
function uuid_schema_alter(&$schema = array()) {
|
||||
$field = uuid_schema_field_definition();
|
||||
foreach (uuid_get_core_entity_info() as $entity_type => $info) {
|
||||
$schema[$info['base table']]['fields'][$info['entity keys']['uuid']] = $field;
|
||||
if (!empty($info['revision table']) && !empty($info['entity keys']['revision uuid'])) {
|
||||
$schema[$info['revision table']]['fields'][$info['entity keys']['revision uuid']] = $field;
|
||||
function uuid_schema_alter(array &$schema) {
|
||||
$field_info = uuid_schema_field_definition();
|
||||
$key_names = array(
|
||||
'base table' => 'uuid',
|
||||
'revision table' => 'revision uuid',
|
||||
);
|
||||
|
||||
foreach (uuid_get_core_entity_info() as $entity_info) {
|
||||
foreach ($key_names as $table_type => $key_name) {
|
||||
if (isset($entity_info[$table_type], $entity_info['entity keys'][$key_name])) {
|
||||
$field_name = $entity_info['entity keys'][$key_name];
|
||||
$properties = array(
|
||||
'fields' => $field_info,
|
||||
'indexes' => array($field_name),
|
||||
);
|
||||
|
||||
foreach ($properties as $property => $value) {
|
||||
$schema[$entity_info[$table_type]][$property][$field_name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,19 +60,20 @@ function uuid_schema_alter(&$schema = array()) {
|
||||
*/
|
||||
function uuid_install() {
|
||||
_uuid_install_uuid_fields();
|
||||
module_load_include('inc', 'uuid');
|
||||
uuid_sync_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the 'uuid' and 'vuuid' fields into Drupal core entity tables where needed.
|
||||
* Install the uuid and vuuid fields for Drupal core entity tables where needed.
|
||||
*
|
||||
* IMPORTANT: This function is called both at install and update time. If this method
|
||||
* is modified to add additional fields in the future, the update strategy must be
|
||||
* considered. See the comment in uuid_update_7102.
|
||||
* IMPORTANT: This function is called both at install and update time. If this
|
||||
* method is modified to add additional fields in the future, the update
|
||||
* strategy must be considered. See the comment in uuid_update_7102.
|
||||
*/
|
||||
function _uuid_install_uuid_fields() {
|
||||
$field = uuid_schema_field_definition();
|
||||
foreach (uuid_get_core_entity_info() as $entity_type => $info) {
|
||||
foreach (uuid_get_core_entity_info() as $info) {
|
||||
if (!db_field_exists($info['base table'], $info['entity keys']['uuid'])) {
|
||||
db_add_field($info['base table'], $info['entity keys']['uuid'], $field);
|
||||
db_add_index($info['base table'], $info['entity keys']['uuid'], array($info['entity keys']['uuid']));
|
||||
@@ -76,7 +91,7 @@ function _uuid_install_uuid_fields() {
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function uuid_uninstall() {
|
||||
foreach (uuid_get_core_entity_info() as $entity_type => $info) {
|
||||
foreach (uuid_get_core_entity_info() as $info) {
|
||||
if (db_field_exists($info['base table'], $info['entity keys']['uuid'])) {
|
||||
db_drop_field($info['base table'], $info['entity keys']['uuid']);
|
||||
db_drop_index($info['base table'], $info['entity keys']['uuid']);
|
||||
@@ -112,8 +127,7 @@ function uuid_update_6001() {
|
||||
}
|
||||
|
||||
/**
|
||||
* For each of out tables, drop the indexe on the UUID column and add a unique
|
||||
* key on that column.
|
||||
* Make all uuid columns unique keys instead of indexes.
|
||||
*/
|
||||
function uuid_update_6002() {
|
||||
$ret = array();
|
||||
@@ -138,8 +152,7 @@ function uuid_update_6003() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix the column definitions for uuid columns in all tables
|
||||
* to use the more efficient char spec.
|
||||
* Change column definitions for uuid columns to more efficient char spec.
|
||||
*/
|
||||
function uuid_update_6004() {
|
||||
$ret = array();
|
||||
@@ -158,6 +171,8 @@ function uuid_update_6004() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Support deleting node revision.
|
||||
*
|
||||
* Modify existing uuid_node_revisions table to support revision deletion, and
|
||||
* add in as much legacy data as possible.
|
||||
*/
|
||||
@@ -204,15 +219,17 @@ function uuid_update_7100() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache for installations that used alpha1. Modules that previously was
|
||||
* enabled in uuid_update_7100() doesn't exist anymore.
|
||||
* Clear cache for installations that used alpha1.
|
||||
*
|
||||
* Modules previously enabled in uuid_update_7100() don't exist any more. We
|
||||
* need to clear the cache so Drupal detects this change.
|
||||
*/
|
||||
function uuid_update_7101() {
|
||||
drupal_flush_all_caches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insure that the uuid and vuuid fields are added where needed.
|
||||
* Ensure that the uuid and vuuid fields are added where needed.
|
||||
*
|
||||
* Note that update 7102 calls _uuid_install_uuid_fields(), which is an
|
||||
* idempotent function. If _uuid_install_uuid_fields() is changed at some
|
||||
@@ -220,8 +237,8 @@ function uuid_update_7101() {
|
||||
* will have run update 7102, and some will not. A new uuid_update_7103()
|
||||
* function would would therefore be necessary to update all users to
|
||||
* the latest schema. At the same time, uuid_update_7102() could become
|
||||
* an empty function, as it would not be necessary to call _uuid_install_uuid_fields()
|
||||
* twice.
|
||||
* an empty function, as it would not be necessary to call
|
||||
* _uuid_install_uuid_fields() twice.
|
||||
*/
|
||||
function uuid_update_7102() {
|
||||
// If the user have disabled the UUID module during upgrade (as UPGRADE.txt
|
||||
@@ -230,3 +247,47 @@ function uuid_update_7102() {
|
||||
_uuid_install_uuid_fields();
|
||||
uuid_sync_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up entities created by uuid_default_entities_example module.
|
||||
*
|
||||
* Modify the labels of all example entities created by the now removed
|
||||
* uuid_default_entities_example.module to make it clear they're examples. Also
|
||||
* remove the administrator role of any example user.
|
||||
*/
|
||||
function uuid_update_7103() {
|
||||
// These are UUIDs of all the example entities that might exist after having
|
||||
// installed uuid_default_entities_example.module.
|
||||
$info = entity_get_info();
|
||||
$uuids = array(
|
||||
'node' => array(
|
||||
'b0558664-c94b-3674-d9df-3e1696b2e471',
|
||||
'5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837',
|
||||
),
|
||||
'user' => array(
|
||||
'7cf875e6-dc15-4404-f190-5a7c3e91d14c',
|
||||
),
|
||||
);
|
||||
// We can't assume taxonomy is enabled.
|
||||
if (isset($info['taxonomy_term'])) {
|
||||
$uuids['taxonomy_term'] = array(
|
||||
'bcb92ce8-2236-e264-65c8-0c163ae716d1',
|
||||
'4293a15c-531a-6164-7d1b-668ed019a6bd',
|
||||
'af738a46-f278-cf84-d94d-9e03879fd71e',
|
||||
);
|
||||
}
|
||||
foreach (array_keys($uuids) as $entity_type) {
|
||||
$info = entity_get_info($entity_type);
|
||||
$entity_ids = entity_get_id_by_uuid($entity_type, $uuids[$entity_type]);
|
||||
$entities = entity_load($entity_type, $entity_ids);
|
||||
foreach ($entities as $entity) {
|
||||
// Update the label to make it clear this is example content.
|
||||
$entity->{$info['entity keys']['label']} = $entity->{$info['entity keys']['label']} . ' (UUID example)';
|
||||
// Remove the administrator role from any user.
|
||||
if ($entity_type == 'user' && $rid = array_search('administrator', $entity->roles)) {
|
||||
unset($entity->roles[$rid]);
|
||||
}
|
||||
entity_save($entity_type, $entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ module_load_include('inc', 'uuid', 'uuid.entity');
|
||||
module_load_include('inc', 'uuid', 'uuid.core');
|
||||
|
||||
/**
|
||||
* Implements of hook_menu().
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function uuid_menu() {
|
||||
$items = array();
|
||||
@@ -34,6 +34,7 @@ function uuid_menu() {
|
||||
'title' => 'UUID redirector',
|
||||
'description' => 'Redirects requests for UUID URIs to the referenced entity.',
|
||||
'page callback' => 'uuid_redirector',
|
||||
// The access check is handled in the page callback.
|
||||
'access callback' => TRUE,
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
@@ -44,7 +45,6 @@ function uuid_menu() {
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('uuid_admin_form'),
|
||||
'access arguments' => array('administer uuid'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
'file' => 'uuid.admin.inc',
|
||||
);
|
||||
|
||||
@@ -72,7 +72,7 @@ function uuid_menu() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_ctools_plugin_directory().
|
||||
* Implements hook_ctools_plugin_directory().
|
||||
*/
|
||||
function uuid_ctools_plugin_directory($module, $plugin) {
|
||||
if ($module == 'ctools') {
|
||||
@@ -81,7 +81,7 @@ function uuid_ctools_plugin_directory($module, $plugin) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_permission().
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function uuid_permission() {
|
||||
return array(
|
||||
@@ -123,9 +123,8 @@ function uuid_hook_info() {
|
||||
return array_fill_keys($hook_names, array('group' => 'uuid'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_views_api().
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function uuid_views_api() {
|
||||
return array(
|
||||
@@ -135,27 +134,27 @@ function uuid_views_api() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_module_implements_alter().
|
||||
* Implements hook_module_implements_alter().
|
||||
*
|
||||
* Moves implementation of hook_entity_info_alter() to the bottom so it is
|
||||
* Moves hook_entity_info_alter() implementation to the bottom so it is
|
||||
* invoked after all modules relying on the entity API.
|
||||
*
|
||||
* @see uuid_entity_info_alter()
|
||||
*/
|
||||
function uuid_module_implements_alter(&$Implementss, $hook) {
|
||||
function uuid_module_implements_alter(&$implementss, $hook) {
|
||||
if ($hook == 'entity_info_alter') {
|
||||
// Move our hook Implements to the bottom.
|
||||
$group = $Implementss['uuid'];
|
||||
unset($Implementss['uuid']);
|
||||
$Implementss['uuid'] = $group;
|
||||
$group = $implementss['uuid'];
|
||||
unset($implementss['uuid']);
|
||||
$implementss['uuid'] = $group;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_uuid_sync().
|
||||
* Implements hook_uuid_sync().
|
||||
*/
|
||||
function uuid_uuid_sync() {
|
||||
foreach (entity_get_info() as $entity_type => $info) {
|
||||
foreach (entity_get_info() as $info) {
|
||||
if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid'])) {
|
||||
_uuid_sync_table($info['base table'], $info['entity keys']['id'], $info['entity keys']['uuid']);
|
||||
if (!empty($info['entity keys']['revision uuid'])) {
|
||||
@@ -185,7 +184,7 @@ function _uuid_sync_table($table, $id_field, $uuid_field) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_features_api().
|
||||
* Implements hook_features_api().
|
||||
*
|
||||
* The Features support consists of exporting entities from a Deploy
|
||||
* <em>fetch-only</em> plan. Deploy is only required to generate the feature
|
||||
@@ -202,7 +201,7 @@ function uuid_features_api() {
|
||||
'default_hook' => 'uuid_default_entities',
|
||||
'default_file' => FEATURES_DEFAULTS_INCLUDED,
|
||||
'feature_source' => TRUE,
|
||||
'file' => drupal_get_path('module', 'uuid') .'/uuid.features.inc',
|
||||
'file' => drupal_get_path('module', 'uuid') . '/uuid.features.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -212,18 +211,22 @@ function uuid_features_api() {
|
||||
*/
|
||||
function uuid_redirector() {
|
||||
$entity_data = uuid_uri_array_to_data(arg());
|
||||
|
||||
|
||||
$entity_info = entity_get_info($entity_data['entity_type']);
|
||||
if (empty($entity_info['uuid'])) {
|
||||
return drupal_not_found();
|
||||
return MENU_NOT_FOUND;
|
||||
}
|
||||
|
||||
$entities = entity_uuid_load($entity_data['entity_type'], array($entity_data['uuid']));
|
||||
if (!count($entities)) {
|
||||
return drupal_not_found();
|
||||
return MENU_NOT_FOUND;
|
||||
}
|
||||
|
||||
$uri = entity_uri($entity_data['entity_type'], current($entities));
|
||||
drupal_goto($uri['path'], array(), 301);
|
||||
}
|
||||
|
||||
if (!drupal_valid_path($uri['path'])) {
|
||||
return MENU_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
drupal_goto($uri['path'], $uri['options'], 301);
|
||||
}
|
||||
|
@@ -6,20 +6,28 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class with some helper methods.
|
||||
* UUID test helper trait.
|
||||
*
|
||||
* Contains methods that assist with running UUID tests.
|
||||
*/
|
||||
class UUIDTestCase extends DrupalWebTestCase {
|
||||
|
||||
function setUp() {
|
||||
parent::setUp(func_get_args());
|
||||
}
|
||||
trait UUIDTestHelper {
|
||||
|
||||
/**
|
||||
* Helper function that asserts a UUID.
|
||||
*/
|
||||
function assertUUID($uuid, $message = NULL) {
|
||||
protected function assertUuid($uuid, $message = NULL) {
|
||||
$this->assertTrue(uuid_is_valid($uuid), $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class with some helper methods.
|
||||
*/
|
||||
abstract class UUIDTestCase extends DrupalWebTestCase {
|
||||
|
||||
use UUIDTestHelper;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,6 +35,9 @@ class UUIDTestCase extends DrupalWebTestCase {
|
||||
*/
|
||||
class UUIDAPITestCase extends UUIDTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'UUID API',
|
||||
@@ -35,26 +46,128 @@ class UUIDAPITestCase extends UUIDTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('uuid');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp(array('uuid'));
|
||||
}
|
||||
|
||||
function testAPIFunctions() {
|
||||
/**
|
||||
* Tests uuid function calls.
|
||||
*/
|
||||
public function testApiFunctions() {
|
||||
// This is a valid UUID, we know that.
|
||||
$valid_uuid = '0ab26e6b-f074-4e44-9da6-1205fa0e9761';
|
||||
// Test the uuid_is_valid() function.
|
||||
$this->assertUUID($valid_uuid, 'UUID validation works.');
|
||||
$this->assertUuid($valid_uuid, 'UUID validation works.');
|
||||
|
||||
// The default generator is 'php'.
|
||||
$uuid = uuid_generate();
|
||||
$this->assertUUID($uuid, 'PHP generator works.');
|
||||
$this->assertUuid($uuid, 'PHP generator works.');
|
||||
|
||||
// Test the 'mysql' generator.
|
||||
variable_set('uuid_generator', 'mysql');
|
||||
drupal_static_reset('uuid_generate');
|
||||
$uuid = uuid_generate();
|
||||
$this->assertUUID($uuid, 'MySQL generator works.');
|
||||
$this->assertUuid($uuid, 'MySQL generator works.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that schema for tables of core entities is correctly defined.
|
||||
*/
|
||||
public function testSchemas() {
|
||||
module_load_include('install', 'uuid');
|
||||
|
||||
$schemas = drupal_get_schema();
|
||||
$field_info = uuid_schema_field_definition();
|
||||
$key_names = array(
|
||||
'base table' => 'uuid',
|
||||
'revision table' => 'revision uuid',
|
||||
);
|
||||
|
||||
foreach (uuid_get_core_entity_info() as $entity_info) {
|
||||
// Test the fields in "base" and "revision" tables.
|
||||
foreach ($key_names as $table_type => $key_name) {
|
||||
// Table or field is not defined in entity.
|
||||
if (!isset($entity_info[$table_type], $entity_info['entity keys'][$key_name])) {
|
||||
// Not all entities have a revisions table.
|
||||
continue;
|
||||
}
|
||||
|
||||
$field_name = $entity_info['entity keys'][$key_name];
|
||||
$table_name = $entity_info[$table_type];
|
||||
|
||||
if (!isset($schemas[$table_name])) {
|
||||
$this->fail(sprintf('Database schema does not have a "%s" table.', $table_name));
|
||||
continue;
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'field' => array('fields', $field_info),
|
||||
'index' => array('indexes', array($field_name)),
|
||||
);
|
||||
|
||||
// Check integrity of the field and index definition.
|
||||
foreach ($properties as $type => $data) {
|
||||
list($property, $value) = $data;
|
||||
|
||||
$message = sprintf('Definition of the "%s" %s in the "%s" schema', $field_name, $type, $table_name);
|
||||
|
||||
if (isset($schemas[$table_name][$property][$field_name])) {
|
||||
$this->assertIdentical($schemas[$table_name][$property][$field_name], $value, "$message is correct.");
|
||||
}
|
||||
else {
|
||||
$this->fail("$message does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the UUID API functions.
|
||||
*/
|
||||
class UUIDV5TestCase extends UUIDTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'UUID v5',
|
||||
'description' => 'Tests the UUID v5 function.',
|
||||
'group' => 'UUID',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp(array('uuid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests uuid function calls.
|
||||
*/
|
||||
public function testV5Function() {
|
||||
// DNS namespace UUID.
|
||||
$dns_namespace = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
||||
|
||||
// Valid DNS generation test.
|
||||
$uuid = uuid_generate_v5($dns_namespace, 'drupal.org');
|
||||
$this->assertUuid($uuid, 'UUID for drupal.org is valid.');
|
||||
$this->assertEqual($uuid, 'c809fd30-48df-52e3-a9f2-2cd78129b8b1', 'UUID for drupal.org is correct.');
|
||||
|
||||
// Invalid namespace test.
|
||||
$invalid_namespace = '01234567-c7a9-feda-27e5-75d00dabc123';
|
||||
$uuid = uuid_generate_v5($invalid_namespace, 'drupal.org');
|
||||
$this->assertFalse($uuid, 'Invalid namespace UUID rejected.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +175,9 @@ class UUIDAPITestCase extends UUIDTestCase {
|
||||
*/
|
||||
class UUIDEntityTestCase extends UUIDTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Entity API functions',
|
||||
@@ -70,14 +186,17 @@ class UUIDEntityTestCase extends UUIDTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('uuid');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp(array('uuid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Entity API's UUID functions.
|
||||
*/
|
||||
function testEntityAPIFunctions() {
|
||||
public function testEntityApiFunctions() {
|
||||
// Create some entities that we will work with.
|
||||
$user = $this->drupalCreateUser();
|
||||
$node = $this->drupalCreateNode(array('title' => 'original title', 'uid' => $user->uid));
|
||||
@@ -94,6 +213,7 @@ class UUIDEntityTestCase extends UUIDTestCase {
|
||||
$vuuids = entity_get_uuid_by_id('node', array($node->vid), TRUE);
|
||||
$this->assertTrue(in_array($node->vuuid, $vuuids), 'Lookup of entity revision UUID works.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +221,9 @@ class UUIDEntityTestCase extends UUIDTestCase {
|
||||
*/
|
||||
class UUIDUserTestCase extends UUIDTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'User implementation',
|
||||
@@ -109,22 +232,26 @@ class UUIDUserTestCase extends UUIDTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$modules = array('uuid');
|
||||
|
||||
// Some tests depends on the optional Entity API module.
|
||||
if (module_exists('entity')) {
|
||||
parent::setUp('uuid', 'entity');
|
||||
}
|
||||
else {
|
||||
parent::setUp('uuid');
|
||||
$modules[] = 'entity';
|
||||
}
|
||||
|
||||
parent::setUp($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CRUD on users with UUID functions.
|
||||
*/
|
||||
function testUserCRUD() {
|
||||
public function testUserCrud() {
|
||||
$user = $this->drupalCreateUser();
|
||||
$this->assertUUID($user->uuid, 'User UUID was generated.');
|
||||
$this->assertUuid($user->uuid, 'User UUID was generated.');
|
||||
|
||||
// Test updating user.
|
||||
$user_test = clone $user;
|
||||
@@ -154,6 +281,7 @@ class UUIDUserTestCase extends UUIDTestCase {
|
||||
$this->assertFalse($user_test, 'Deleting user with UUID worked.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,6 +289,9 @@ class UUIDUserTestCase extends UUIDTestCase {
|
||||
*/
|
||||
class UUIDNodeTestCase extends UUIDTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Node implementation',
|
||||
@@ -169,35 +300,46 @@ class UUIDNodeTestCase extends UUIDTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$modules = array('uuid');
|
||||
|
||||
// Some tests depends on the optional Entity API module.
|
||||
if (module_exists('entity')) {
|
||||
parent::setUp('uuid', 'entity');
|
||||
}
|
||||
else {
|
||||
parent::setUp('uuid');
|
||||
$modules[] = 'entity';
|
||||
}
|
||||
|
||||
parent::setUp($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests CRUD on nodes with UUID functions.
|
||||
*
|
||||
* @todo
|
||||
* Break out into multiple test methods to loosen coupling between tests.
|
||||
*/
|
||||
function testNodeCRUD() {
|
||||
public function testNodeCrud() {
|
||||
// Create some entities that we will work with.
|
||||
$user = $this->drupalCreateUser();
|
||||
$node = $this->drupalCreateNode(array('title' => 'original title', 'uid' => $user->uid));
|
||||
|
||||
$this->assertUUID($node->uuid, 'Node UUID was generated.');
|
||||
$this->assertUUID($node->vuuid, 'Node revision UUID was generated.');
|
||||
$this->assertUuid($node->uuid, 'Node UUID was generated.');
|
||||
$this->assertUuid($node->vuuid, 'Node revision UUID was generated.');
|
||||
|
||||
// Test node update, without creating new revision.
|
||||
$node_test = clone $node;
|
||||
$node_test->title = 'new title';
|
||||
$node_test->title = 'original title';
|
||||
$node_test->revision = FALSE;
|
||||
node_save($node_test);
|
||||
$node_test = node_load($node->nid, FALSE, TRUE);
|
||||
$this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after update, when not creating new revision.');
|
||||
$this->assertEqual($node_test->vuuid, $node->vuuid, 'Node revision UUID was intact after updating, when not creating new revision.');
|
||||
// Save the original revision IDs that we will test with later.
|
||||
$vid_old = $node_test->vid;
|
||||
$vuuid_old = $node_test->vuuid;
|
||||
$uuid_old = $node_test->uuid;
|
||||
|
||||
// Test node update, with new revision.
|
||||
$node_test = clone $node;
|
||||
@@ -207,13 +349,31 @@ class UUIDNodeTestCase extends UUIDTestCase {
|
||||
$node_test = node_load($node->nid, FALSE, TRUE);
|
||||
$this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after updating, when creating new revision.');
|
||||
$this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revision UUID was generated, when creating new revision.');
|
||||
$this->assertUUID($node_test->vuuid, 'The new node revision UUID was valid.');
|
||||
$this->assertUuid($node_test->vuuid, 'The new node revision UUID was valid.');
|
||||
|
||||
// Test entity_uuid_load().
|
||||
// Save some variables that we will test against.
|
||||
$nid_test = $node_test->nid;
|
||||
$vid_test = $node_test->vid;
|
||||
$uid_test = $user->uuid;
|
||||
$uuid_test = $node_test->uuid;
|
||||
$vuuid_test = $node_test->vuuid;
|
||||
$nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
|
||||
$node_test = reset($nodes);
|
||||
$this->assertEqual($node_test->nid, $node->nid, 'Node was correctly loaded with UUID.');
|
||||
$this->assertEqual($node_test->uid, $user->uuid, "Node property 'uid' was transformed to UUID when loaded with UUID.");
|
||||
$this->assertEqual($node_test->nid, $nid_test, 'Node ID was correct when loading with UUID.');
|
||||
$this->assertEqual($node_test->vid, $vid_test, 'Node revision ID was correct when loading with UUID.');
|
||||
$this->assertEqual($node_test->uid, $uid_test, "Node author ID was transformed to UUID when loaded with UUID.");
|
||||
$this->assertEqual($node_test->uuid, $uuid_test, 'Node UUID was correct when loading with UUID.');
|
||||
$this->assertEqual($node_test->vuuid, $vuuid_test, 'Node revision UUID was correct when loading with UUID.');
|
||||
|
||||
// Test entity_uuid_load() with conditions.
|
||||
// Load the previous revision UUID that we saved earlier.
|
||||
$nodes = entity_uuid_load('node', array($uuid_test), array('vuuid' => $vuuid_old));
|
||||
$node_test = reset($nodes);
|
||||
$this->assertTrue((($node_test->uuid == $uuid_test) && ($node_test->nid && $node->nid)), 'The correct entity was loaded when loading a universal entity with a revision UUID condition.');
|
||||
$this->assertEqual($node_test->vuuid, $vuuid_old, 'Correct revision UUID was loaded when loading a universal entity with a revision UUID condition.');
|
||||
$this->assertEqual($node_test->vid, $vid_old, 'Correct revision ID was loaded when loading a universal entity with a revision UUID condition.');
|
||||
$this->assertEqual($node_test->title, 'original title', 'Correct title was loaded when loading a universal entity with a revision UUID condition.');
|
||||
|
||||
// The following tests depends on the optional Entity API module.
|
||||
if (module_exists('entity')) {
|
||||
@@ -245,15 +405,79 @@ class UUIDNodeTestCase extends UUIDTestCase {
|
||||
$this->assertEqual($node_test->title, 'newer title', 'Saving node with UUID mapped to correct node, when creating new revision.');
|
||||
$this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after saving with UUID, when creating new revision.');
|
||||
$this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revison UUID was generated after saving with UUID, when creating new revision.');
|
||||
$this->assertUUID($node_test->vuuid, 'New node revision UUID was valid.');
|
||||
$this->assertUuid($node_test->vuuid, 'New node revision UUID was valid.');
|
||||
$this->assertEqual($node_test->uid, $node->uid, "Node property 'uid' was intact after saving with UUID, when creating new revision.");
|
||||
|
||||
// Test the same thing again, but now triggering a new revision from a
|
||||
// remote environment.
|
||||
// TODO: Move this test to the uuid_services module.
|
||||
$nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
|
||||
$node_test = reset($nodes);
|
||||
// Store the current local revision ID to test with later.
|
||||
$vid_old1 = $node_test->vid;
|
||||
// Simulate this node coming from a remote environment by generating
|
||||
// IDs that won't match. Only the UUID match at this point.
|
||||
$node_test->uuid_services = TRUE;
|
||||
$vuuid_test = uuid_generate();
|
||||
$node_test->nid = $nid_test;
|
||||
$node_test->vid = $vid_test;
|
||||
$node_test->vuuid = $vuuid_test;
|
||||
$node_test->revision = TRUE;
|
||||
entity_uuid_save('node', $node_test);
|
||||
$node_test = node_load($node->nid, FALSE, TRUE);
|
||||
$this->assertNotEqual($node_test->vid, $vid_old1, 'A new revision was created, when trying to create new revision with new revision UUID from remote site');
|
||||
$this->assertEqual($node_test->vuuid, $vuuid_test, 'The revison UUID was preserved after saving with UUID, when trying to create new revision with new revision UUID from remote site.');
|
||||
|
||||
// Test the same thing again from a remote environment, but now with the
|
||||
// same vuuid as once previosuly. This should not trigger a new revision.
|
||||
// This covers the case of "dupe deployments" where a client might push a
|
||||
// node several times.
|
||||
// TODO: Move this test to the uuid_services module.
|
||||
$nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
|
||||
$node_test = reset($nodes);
|
||||
// Store the current local revision ID to test with later.
|
||||
$vid_old2 = $node_test->vid;
|
||||
// Simulate this node coming from a remote environment by generating
|
||||
// IDs that won't match.
|
||||
$node_test->uuid_services = TRUE;
|
||||
$node_test->nid = $nid_test;
|
||||
$node_test->vid = $vid_test;
|
||||
$node_test->vuuid = $vuuid_test;
|
||||
$node_test->revision = TRUE;
|
||||
entity_uuid_save('node', $node_test);
|
||||
$node_test = node_load($node->nid, FALSE, TRUE);
|
||||
$this->assertEqual($node_test->vid, $vid_old2, 'A new revision was not created, when trying to create new revision with existing revision UUID from remote site.');
|
||||
$this->assertEqual($node_test->vuuid, $vuuid_test, 'The revison UUID was preserved after saving with UUID, when trying to create new revision with existing revision UUID from remote site.');
|
||||
|
||||
// Test the same this again, but now with an old revision.
|
||||
$nodes = entity_uuid_load('node', array($uuid_old), array('vuuid' => $vuuid_old), TRUE);
|
||||
$node_test = reset($nodes);
|
||||
// Simulate this node coming from a remote environment by generating
|
||||
// IDs that won't match.
|
||||
$node_test->uuid_services = TRUE;
|
||||
$node_test->nid = rand();
|
||||
$node_test->vid = rand();
|
||||
$node_test->revision = TRUE;
|
||||
$node_test->title = 'newest title';
|
||||
entity_uuid_save('node', $node_test);
|
||||
$node_test = node_load($node->nid, $vid_old, TRUE);
|
||||
$this->assertEqual($node_test->title, 'newest title', 'The revision was updated, when updating old revision with existing revision UUID from remote site.');
|
||||
$this->assertEqual($node_test->vuuid, $vuuid_old, 'The revison UUID was preserved after saving with UUID, when updating old revision with existing revision UUID from remote site.');
|
||||
|
||||
// Setting the node options variable should also trigger a new revision.
|
||||
$nodes = entity_uuid_load('node', array($node->uuid), array(), TRUE);
|
||||
$node_test = reset($nodes);
|
||||
variable_set('node_options_' . $node_test->type, array('revision'));
|
||||
entity_uuid_save('node', $node_test);
|
||||
$this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revison ID was generated after saving with UUID, when relying on the node options variable.');
|
||||
|
||||
// Test entity_uuid_delete() for nodes.
|
||||
entity_uuid_delete('node', $node->uuid);
|
||||
$node_test = node_load($node->nid);
|
||||
$this->assertFalse($node_test, 'Deleting node with UUID worked.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,6 +488,11 @@ class UUIDNodeTestCase extends UUIDTestCase {
|
||||
*/
|
||||
class UUIDCommentTestCase extends CommentHelperCase {
|
||||
|
||||
use UUIDTestHelper;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Comment implementation',
|
||||
@@ -272,31 +501,21 @@ class UUIDCommentTestCase extends CommentHelperCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that asserts a UUID.
|
||||
*
|
||||
* We have duplicated this function from UUIDTestCase since we have to extend
|
||||
* CommentHelperCase instead.
|
||||
*/
|
||||
function assertUUID($uuid, $message = NULL) {
|
||||
$this->assertTrue(uuid_is_valid($uuid), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CRUD on comments with UUID functions.
|
||||
*/
|
||||
function testCommentCRUD() {
|
||||
public function testCommentCrud() {
|
||||
// This is sub optimal, but due to how CommentHelperCase::setUp() is
|
||||
// constructed we are enforced to do this. So unfortunately this test
|
||||
// depends on 'entity' module for now.
|
||||
module_enable(array('uuid', 'entity'), TRUE);
|
||||
module_enable(array('uuid', 'entity'));
|
||||
$user = $this->drupalCreateUser();
|
||||
$this->drupalLogin($user);
|
||||
$node = $this->drupalCreateNode();
|
||||
$return = $this->postComment($node, 'Lorem ipsum');
|
||||
|
||||
$comment = comment_load($return->id);
|
||||
$this->assertUUID($comment->uuid, 'Comment UUID was generated.');
|
||||
$this->assertUuid($comment->uuid, 'Comment UUID was generated.');
|
||||
|
||||
// Test updating comment.
|
||||
$comment_test = clone $comment;
|
||||
@@ -332,6 +551,7 @@ class UUIDCommentTestCase extends CommentHelperCase {
|
||||
$this->assertFalse($comment_test, 'Deleting comment with UUID worked.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,6 +559,11 @@ class UUIDCommentTestCase extends CommentHelperCase {
|
||||
*/
|
||||
class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
|
||||
|
||||
use UUIDTestHelper;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Taxonomy implementation',
|
||||
@@ -348,40 +573,38 @@ class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* A lot of code here is taken from TaxonomyTermTestCase::setUp().
|
||||
*/
|
||||
function setUp() {
|
||||
protected function setUp() {
|
||||
$modules = array('taxonomy', 'uuid');
|
||||
|
||||
// Some tests depends on the optional Entity API module.
|
||||
if (module_exists('entity')) {
|
||||
parent::setUp('taxonomy', 'uuid', 'entity');
|
||||
$modules[] = 'entity';
|
||||
}
|
||||
else {
|
||||
parent::setUp('taxonomy', 'uuid');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that asserts a UUID.
|
||||
*
|
||||
* We have duplicated this function from UUIDTestCase since we have to extend
|
||||
* TaxonomyWebTestCase instead.
|
||||
*/
|
||||
function assertUUID($uuid, $message = NULL) {
|
||||
$this->assertTrue(uuid_is_valid($uuid), $message);
|
||||
parent::setUp($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CRUD on comments with UUID functions.
|
||||
*/
|
||||
function testTaxonomyCRUD() {
|
||||
$user = $this->drupalCreateUser(array('administer taxonomy', 'administer nodes', 'bypass node access'));
|
||||
public function testTaxonomyCrud() {
|
||||
$perms = array(
|
||||
'administer taxonomy',
|
||||
'administer nodes',
|
||||
'bypass node access',
|
||||
);
|
||||
$user = $this->drupalCreateUser($perms);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Create a term by tagging a node. We'll use this node later too.
|
||||
$vocabulary = new stdClass;
|
||||
$vocabulary = new stdClass();
|
||||
$vocabulary->vid = 1;
|
||||
$term = $this->createTerm($vocabulary);
|
||||
$this->assertUUID($term->uuid, 'Term UUID was generated.');
|
||||
$this->assertUuid($term->uuid, 'Term UUID was generated.');
|
||||
|
||||
// Test updating term.
|
||||
$term_test = clone $term;
|
||||
@@ -413,6 +636,7 @@ class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
|
||||
$this->assertFalse($term_test, 'Deleting term with UUID worked.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,6 +644,9 @@ class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
|
||||
*/
|
||||
class UUIDSyncTestCase extends UUIDTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'UUID sync',
|
||||
@@ -434,19 +661,14 @@ class UUIDSyncTestCase extends UUIDTestCase {
|
||||
* @todo
|
||||
* There are something weird around this assertion.
|
||||
*/
|
||||
function assertTableColumn($table, $column, $message) {
|
||||
$result = db_query("SHOW COLUMNS FROM {$table}");
|
||||
$exists = FALSE;
|
||||
foreach ($result as $record) {
|
||||
if ($record->field == $column) {
|
||||
$exists = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertTrue($exists, $message);
|
||||
protected function assertTableColumn($table, $column, $message) {
|
||||
$this->assertTrue(db_field_exists($table, $column), $message);
|
||||
}
|
||||
|
||||
function testSync() {
|
||||
/**
|
||||
* Tests creating UUIDs for entities that don't have them.
|
||||
*/
|
||||
public function testSync() {
|
||||
// These entities will not have UUID from the start, since the UUID module
|
||||
// isn't installed yet.
|
||||
$user = $this->drupalCreateUser();
|
||||
@@ -473,218 +695,12 @@ class UUIDSyncTestCase extends UUIDTestCase {
|
||||
|
||||
// Test if UUID was generated for nodes.
|
||||
$node_test = node_load($node->nid, FALSE, TRUE);
|
||||
$this->assertUUID($node_test->uuid, 'Node UUID was generated when clicking the sync button.');
|
||||
$this->assertUUID($node_test->vuuid, 'Node revision UUID was generated when clicking the sync button.');
|
||||
$this->assertUuid($node_test->uuid, 'Node UUID was generated when clicking the sync button.');
|
||||
$this->assertUuid($node_test->vuuid, 'Node revision UUID was generated when clicking the sync button.');
|
||||
|
||||
// Test if UUID was generated for users.
|
||||
$user_test = user_load($user->uid, TRUE);
|
||||
$this->assertUUID($user_test->uuid, 'User UUID was generated when clicking the sync button.');
|
||||
}
|
||||
}
|
||||
|
||||
class UUIDExportEntitiesWithDeploy extends DrupalWebTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Export UUID entities',
|
||||
'description' => 'Test exporting UUID entities with Deploy and Features.',
|
||||
'group' => 'UUID',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('taxonomy', 'uuid', 'entity', 'features', 'deploy', 'deploy_example');
|
||||
}
|
||||
|
||||
function testExport() {
|
||||
$test_user = $this->drupalCreateUser();
|
||||
$test_node = $this->drupalCreateNode(array(
|
||||
'uid' => $test_user->uid,
|
||||
));
|
||||
deploy_manager_add_to_plan('deploy_example_plan', 'node', $test_node);
|
||||
// TODO: Test the actual insert.
|
||||
$this->assertTrue(TRUE, 'Added a node with a user dependency to be exported as a Feature module.');
|
||||
|
||||
// Login and recreate the example feature. The feature isn't installed. But
|
||||
// Features can still export the code, and we can test it.
|
||||
$web_user = $this->drupalCreateUser(array('administer features'));
|
||||
$this->drupalLogin($web_user);
|
||||
$code = $this->drupalPost('admin/structure/features/uuid_default_entities_example/recreate', array(), t('Download feature'));
|
||||
$this->assertTrue($code, 'Feature module was exported.');
|
||||
|
||||
// Ensure that we find what we expect in the exported code.
|
||||
$node_test1 = preg_match('/' . $test_node->title . '/', $code);
|
||||
$node_test2 = preg_match("/'uri' => 'node\/" . $test_node->uuid . "'/", $code);
|
||||
$this->assertTrue($node_test1, 'Node title was found in the expoted code.');
|
||||
$this->assertTrue($node_test2, 'Node URI was found in the expoted code.');
|
||||
$user_test1 = preg_match('/' . $test_user->name . '/', $code);
|
||||
$user_test2 = preg_match("/'uri' => 'user\/" . $test_user->uuid . "'/", $code);
|
||||
$this->assertTrue($user_test1, 'User was found in the expoted code.');
|
||||
$this->assertTrue($user_test2, 'User URI was found in the expoted code.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the UUID synchronization.
|
||||
*/
|
||||
class UUIDImportEntitiesTestCase extends UUIDTestCase {
|
||||
|
||||
/**
|
||||
* Representation of the UUIDs that is exported in our example feature, that
|
||||
* we use for testing.
|
||||
*/
|
||||
public $term1_uuid = 'bcb92ce8-2236-e264-65c8-0c163ae716d1';
|
||||
public $term2_uuid = '4293a15c-531a-6164-7d1b-668ed019a6bd';
|
||||
public $term3_uuid = 'af738a46-f278-cf84-d94d-9e03879fd71e';
|
||||
public $node1_uuid = 'b0558664-c94b-3674-d9df-3e1696b2e471';
|
||||
public $node2_uuid = '5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837';
|
||||
public $user1_uuid = '7cf875e6-dc15-4404-f190-5a7c3e91d14c';
|
||||
|
||||
/**
|
||||
* Helper method to assert the uuid_entities component in any features.
|
||||
*/
|
||||
function assertFeatureState($feature, $state, $message = '') {
|
||||
if (empty($message)) {
|
||||
switch ($state) {
|
||||
case FEATURES_DEFAULT:
|
||||
$readable_state = 'default';
|
||||
break;
|
||||
case FEATURES_OVERRIDDEN:
|
||||
$readable_state = 'overridden';
|
||||
break;
|
||||
default:
|
||||
$readable_state = 'unknown';
|
||||
break;
|
||||
}
|
||||
$message = format_string('%component in %feature had state: %state', array('%component' => 'uuid_entities', '%feature' => $feature, '%state' => $readable_state));
|
||||
}
|
||||
// Ensure that the features we used is in default state.
|
||||
$states = features_get_component_states(array($feature), TRUE, TRUE);
|
||||
if (!$this->assertEqual($states[$feature]['uuid_entities'], $state, $message)) {
|
||||
debug(format_string('Enabling functionality to show diff output for debug purposes.'));
|
||||
$success = module_enable(array('diff'));
|
||||
if ($success) {
|
||||
// Make sure we run on cold caches.
|
||||
drupal_flush_all_caches();
|
||||
drupal_static_reset();
|
||||
|
||||
$user = $this->drupalCreateUser(array('administer features'));
|
||||
$this->drupalLogin($user);
|
||||
$this->drupalGet('admin/structure/features/' . $feature . '/diff');
|
||||
}
|
||||
else {
|
||||
debug(format_string('Download !module to see diff output for debug purposes.', array('!module' => 'diff.module')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getEntityByUuid($entity_type, $uuid) {
|
||||
$ids = entity_get_id_by_uuid($entity_type, array($uuid));
|
||||
$entities = entity_load($entity_type, $ids, NULL, TRUE);
|
||||
return reset($entities);
|
||||
}
|
||||
|
||||
function enableFeature($feature) {
|
||||
$success = module_enable(array($feature), TRUE);
|
||||
$this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', array($feature)))));
|
||||
// Make sure we run on cold caches.
|
||||
drupal_flush_all_caches();
|
||||
drupal_static_reset();
|
||||
}
|
||||
|
||||
function revertFeature($feature) {
|
||||
features_revert(array($feature => array('uuid_entities')));
|
||||
$this->assertTrue(TRUE, format_string('Reverted feature: %feature', array('%feature' => $feature)));
|
||||
}
|
||||
|
||||
function testImport() {
|
||||
$term1 = $this->getEntityByUuid('taxonomy_term', $this->term1_uuid);
|
||||
$term2 = $this->getEntityByUuid('taxonomy_term', $this->term2_uuid);
|
||||
$term3 = $this->getEntityByUuid('taxonomy_term', $this->term3_uuid);
|
||||
$node1 = $this->getEntityByUuid('node', $this->node1_uuid);
|
||||
$node2 = $this->getEntityByUuid('node', $this->node2_uuid);
|
||||
$user1 = $this->getEntityByUuid('user', $this->user1_uuid);
|
||||
|
||||
// Ensure that we don't have our entities yet.
|
||||
$this->assertTrue(empty($term1), 'Term 1 has not been created yet.');
|
||||
$this->assertTrue(empty($term2), 'Term 2 has not been created yet.');
|
||||
$this->assertTrue(empty($term3), 'Term 3 has not been created yet.');
|
||||
$this->assertTrue(empty($node1), 'Node 1 has not been created yet.');
|
||||
$this->assertTrue(empty($node2), 'Node 2 has not been created yet.');
|
||||
$this->assertTrue(empty($user1), 'User 1 has not been created yet.');
|
||||
|
||||
$this->enableFeature('uuid_default_entities_example');
|
||||
|
||||
$term1 = $this->getEntityByUuid('taxonomy_term', $this->term1_uuid);
|
||||
$term2 = $this->getEntityByUuid('taxonomy_term', $this->term2_uuid);
|
||||
$term3 = $this->getEntityByUuid('taxonomy_term', $this->term3_uuid);
|
||||
$node1 = $this->getEntityByUuid('node', $this->node1_uuid);
|
||||
$node2 = $this->getEntityByUuid('node', $this->node2_uuid);
|
||||
$user1 = $this->getEntityByUuid('user', $this->user1_uuid);
|
||||
|
||||
// Ensure that our entities was created.
|
||||
$this->assertEqual($term1->uuid, $this->term1_uuid, 'Term 1 was created.');
|
||||
$this->assertEqual($term2->uuid, $this->term2_uuid, 'Term 2 was created.');
|
||||
$this->assertEqual($term3->uuid, $this->term3_uuid, 'Term 3 was created.');
|
||||
$this->assertEqual($node1->uuid, $this->node1_uuid, 'Node 1 was created.');
|
||||
$this->assertEqual($node2->uuid, $this->node2_uuid, 'Node 2 was created.');
|
||||
$this->assertEqual($user1->uuid, $this->user1_uuid, 'User 1 was created.');
|
||||
|
||||
// Check the features state.
|
||||
$this->assertFeatureState('uuid_default_entities_example', FEATURES_DEFAULT);
|
||||
|
||||
// New property.
|
||||
$new = 'foo bar';
|
||||
// Change a term.
|
||||
$term1->name = $new;
|
||||
$status = taxonomy_term_save($term1);
|
||||
$this->assertEqual($status, SAVED_UPDATED, 'Updated term 1.');
|
||||
// Change a node.
|
||||
$node1->title = $new;
|
||||
node_save($node1);
|
||||
$this->assertEqual($node1->title, $new, 'Updated node 1.');
|
||||
// Change a user.
|
||||
$user1->name = $new;
|
||||
$updated_user = user_save($user1);
|
||||
$this->assertEqual($user1->name, $updated_user->name, 'Updated user 1.');
|
||||
|
||||
// Check the features state.
|
||||
$this->assertFeatureState('uuid_default_entities_example', FEATURES_OVERRIDDEN);
|
||||
|
||||
// Revert the feature.
|
||||
$this->revertFeature('uuid_default_entities_example');
|
||||
|
||||
// Check the features state.
|
||||
$this->assertFeatureState('uuid_default_entities_example', FEATURES_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
class UUIDImportEntitiesWithDeploy extends UUIDImportEntitiesTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Import UUID entities, with Deploy',
|
||||
'description' => 'Test importing UUID entities with Features and Deploy.',
|
||||
'group' => 'UUID',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('taxonomy', 'uuid', 'entity', 'features', 'deploy', 'deploy_example');
|
||||
}
|
||||
}
|
||||
|
||||
class UUIDImportEntitiesWithoutDeploy extends UUIDImportEntitiesTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Import UUID entities, without Deploy',
|
||||
'description' => 'Test importing UUID entities with Features only.',
|
||||
'group' => 'UUID',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('taxonomy', 'uuid', 'entity', 'features');
|
||||
$this->assertUuid($user_test->uuid, 'User UUID was generated when clicking the sync button.');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -28,6 +28,20 @@ function uuid_token_info() {
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_token_info_alter().
|
||||
*/
|
||||
function uuid_token_info_alter(&$data) {
|
||||
foreach (entity_get_info() as $entity_type => $info) {
|
||||
if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid'])) {
|
||||
$token_type = !empty($info['token type']) ? $info['token type'] : $entity_type;
|
||||
if (empty($data['types'][$token_type])) {
|
||||
unset($data['tokens'][$token_type]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views Implementation for UUID
|
||||
* Views Implementation for UUID.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@@ -1,402 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* uuid_default_entities_example.features.uuid_entities.inc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_default_entities().
|
||||
*/
|
||||
function uuid_default_entities_example_uuid_default_entities() {
|
||||
$entities = array();
|
||||
|
||||
$entities['deploy_example_plan'][] = (object) array(
|
||||
'__metadata' => array(
|
||||
'type' => 'taxonomy_term',
|
||||
'uri' => 'taxonomy_term/bcb92ce8-2236-e264-65c8-0c163ae716d1',
|
||||
'cause' => 'node/b0558664-c94b-3674-d9df-3e1696b2e471',
|
||||
),
|
||||
'description' => NULL,
|
||||
'format' => NULL,
|
||||
'name' => 'Foo',
|
||||
'path' => array(
|
||||
'alias' => 'term/foo',
|
||||
),
|
||||
'rdf_mapping' => array(
|
||||
'rdftype' => array(
|
||||
0 => 'skos:Concept',
|
||||
),
|
||||
'name' => array(
|
||||
'predicates' => array(
|
||||
0 => 'rdfs:label',
|
||||
1 => 'skos:prefLabel',
|
||||
),
|
||||
),
|
||||
'description' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:definition',
|
||||
),
|
||||
),
|
||||
'vid' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:inScheme',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'parent' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:broader',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
),
|
||||
'uuid' => 'bcb92ce8-2236-e264-65c8-0c163ae716d1',
|
||||
'vocabulary_machine_name' => 'tags',
|
||||
'weight' => '0',
|
||||
);
|
||||
$entities['deploy_example_plan'][] = (object) array(
|
||||
'__metadata' => array(
|
||||
'type' => 'taxonomy_term',
|
||||
'uri' => 'taxonomy_term/4293a15c-531a-6164-7d1b-668ed019a6bd',
|
||||
'cause' => 'node/b0558664-c94b-3674-d9df-3e1696b2e471',
|
||||
),
|
||||
'description' => NULL,
|
||||
'format' => NULL,
|
||||
'name' => 'Bar',
|
||||
'rdf_mapping' => array(
|
||||
'rdftype' => array(
|
||||
0 => 'skos:Concept',
|
||||
),
|
||||
'name' => array(
|
||||
'predicates' => array(
|
||||
0 => 'rdfs:label',
|
||||
1 => 'skos:prefLabel',
|
||||
),
|
||||
),
|
||||
'description' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:definition',
|
||||
),
|
||||
),
|
||||
'vid' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:inScheme',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'parent' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:broader',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
),
|
||||
'uuid' => '4293a15c-531a-6164-7d1b-668ed019a6bd',
|
||||
'vocabulary_machine_name' => 'tags',
|
||||
'weight' => '0',
|
||||
);
|
||||
$entities['deploy_example_plan'][] = (object) array(
|
||||
'__metadata' => array(
|
||||
'type' => 'node',
|
||||
'uri' => 'node/b0558664-c94b-3674-d9df-3e1696b2e471',
|
||||
'cause' => FALSE,
|
||||
),
|
||||
'body' => array(
|
||||
'und' => array(
|
||||
0 => array(
|
||||
'format' => 'filtered_html',
|
||||
'summary' => '',
|
||||
'value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
|
||||
),
|
||||
),
|
||||
),
|
||||
'cid' => '0',
|
||||
'comment' => '2',
|
||||
'comment_count' => '0',
|
||||
'field_image' => array(),
|
||||
'field_tags' => array(
|
||||
'und' => array(
|
||||
0 => array(
|
||||
'tid' => 'bcb92ce8-2236-e264-65c8-0c163ae716d1',
|
||||
),
|
||||
1 => array(
|
||||
'tid' => '4293a15c-531a-6164-7d1b-668ed019a6bd',
|
||||
),
|
||||
),
|
||||
),
|
||||
'language' => 'und',
|
||||
'last_comment_name' => NULL,
|
||||
'last_comment_uid' => '1',
|
||||
'log' => '',
|
||||
'path' => array(
|
||||
'alias' => 'lorem-ipsum',
|
||||
),
|
||||
'promote' => '1',
|
||||
'rdf_mapping' => array(
|
||||
'field_image' => array(
|
||||
'predicates' => array(
|
||||
0 => 'og:image',
|
||||
1 => 'rdfs:seeAlso',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'field_tags' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:subject',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'rdftype' => array(
|
||||
0 => 'sioc:Item',
|
||||
1 => 'foaf:Document',
|
||||
),
|
||||
'title' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:title',
|
||||
),
|
||||
),
|
||||
'created' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:date',
|
||||
1 => 'dc:created',
|
||||
),
|
||||
'datatype' => 'xsd:dateTime',
|
||||
'callback' => 'date_iso8601',
|
||||
),
|
||||
'changed' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:modified',
|
||||
),
|
||||
'datatype' => 'xsd:dateTime',
|
||||
'callback' => 'date_iso8601',
|
||||
),
|
||||
'body' => array(
|
||||
'predicates' => array(
|
||||
0 => 'content:encoded',
|
||||
),
|
||||
),
|
||||
'uid' => array(
|
||||
'predicates' => array(
|
||||
0 => 'sioc:has_creator',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'name' => array(
|
||||
'predicates' => array(
|
||||
0 => 'foaf:name',
|
||||
),
|
||||
),
|
||||
'comment_count' => array(
|
||||
'predicates' => array(
|
||||
0 => 'sioc:num_replies',
|
||||
),
|
||||
'datatype' => 'xsd:integer',
|
||||
),
|
||||
'last_activity' => array(
|
||||
'predicates' => array(
|
||||
0 => 'sioc:last_activity_date',
|
||||
),
|
||||
'datatype' => 'xsd:dateTime',
|
||||
'callback' => 'date_iso8601',
|
||||
),
|
||||
),
|
||||
'status' => '1',
|
||||
'sticky' => '0',
|
||||
'title' => 'Lorem ipsum',
|
||||
'tnid' => '0',
|
||||
'translate' => '0',
|
||||
'type' => 'article',
|
||||
'uid' => '1',
|
||||
'uuid' => 'b0558664-c94b-3674-d9df-3e1696b2e471',
|
||||
);
|
||||
$entities['deploy_example_plan'][] = (object) array(
|
||||
'__metadata' => array(
|
||||
'type' => 'taxonomy_term',
|
||||
'uri' => 'taxonomy_term/af738a46-f278-cf84-d94d-9e03879fd71e',
|
||||
'cause' => 'node/5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837',
|
||||
),
|
||||
'description' => NULL,
|
||||
'format' => NULL,
|
||||
'name' => 'Baz',
|
||||
'rdf_mapping' => array(
|
||||
'rdftype' => array(
|
||||
0 => 'skos:Concept',
|
||||
),
|
||||
'name' => array(
|
||||
'predicates' => array(
|
||||
0 => 'rdfs:label',
|
||||
1 => 'skos:prefLabel',
|
||||
),
|
||||
),
|
||||
'description' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:definition',
|
||||
),
|
||||
),
|
||||
'vid' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:inScheme',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'parent' => array(
|
||||
'predicates' => array(
|
||||
0 => 'skos:broader',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
),
|
||||
'uuid' => 'af738a46-f278-cf84-d94d-9e03879fd71e',
|
||||
'vocabulary_machine_name' => 'tags',
|
||||
'weight' => '0',
|
||||
);
|
||||
$entities['deploy_example_plan'][] = (object) array(
|
||||
'__metadata' => array(
|
||||
'type' => 'user',
|
||||
'uri' => 'user/7cf875e6-dc15-4404-f190-5a7c3e91d14c',
|
||||
'cause' => 'node/5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837',
|
||||
),
|
||||
'init' => 'no@example.com',
|
||||
'language' => '',
|
||||
'mail' => 'no@example.com',
|
||||
'name' => 'mohamed',
|
||||
'pass' => '$S$DtyVr4YQkvCpofZdLT4.L23Xb6E8HUkmEgZikN919RTZXZSePwso',
|
||||
'picture' => NULL,
|
||||
'rdf_mapping' => array(
|
||||
'rdftype' => array(
|
||||
0 => 'sioc:UserAccount',
|
||||
),
|
||||
'name' => array(
|
||||
'predicates' => array(
|
||||
0 => 'foaf:name',
|
||||
),
|
||||
),
|
||||
'homepage' => array(
|
||||
'predicates' => array(
|
||||
0 => 'foaf:page',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
),
|
||||
'roles' => array(
|
||||
2 => 'authenticated user',
|
||||
3 => 'administrator',
|
||||
),
|
||||
'signature' => '',
|
||||
'signature_format' => 'filtered_html',
|
||||
'status' => '1',
|
||||
'theme' => '',
|
||||
'timezone' => 'Asia/Riyadh',
|
||||
'uuid' => '7cf875e6-dc15-4404-f190-5a7c3e91d14c',
|
||||
);
|
||||
$entities['deploy_example_plan'][] = (object) array(
|
||||
'__metadata' => array(
|
||||
'type' => 'node',
|
||||
'uri' => 'node/5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837',
|
||||
'cause' => FALSE,
|
||||
),
|
||||
'body' => array(
|
||||
'und' => array(
|
||||
0 => array(
|
||||
'format' => 'filtered_html',
|
||||
'summary' => '',
|
||||
'value' => 'Nunc sollicitudin justo ut augue egestas et varius quam consectetur.',
|
||||
),
|
||||
),
|
||||
),
|
||||
'cid' => '0',
|
||||
'comment' => '2',
|
||||
'comment_count' => '0',
|
||||
'field_image' => array(),
|
||||
'field_tags' => array(
|
||||
'und' => array(
|
||||
0 => array(
|
||||
'tid' => 'af738a46-f278-cf84-d94d-9e03879fd71e',
|
||||
),
|
||||
),
|
||||
),
|
||||
'language' => 'und',
|
||||
'last_comment_name' => NULL,
|
||||
'last_comment_uid' => '7cf875e6-dc15-4404-f190-5a7c3e91d14c',
|
||||
'log' => '',
|
||||
'promote' => '1',
|
||||
'rdf_mapping' => array(
|
||||
'field_image' => array(
|
||||
'predicates' => array(
|
||||
0 => 'og:image',
|
||||
1 => 'rdfs:seeAlso',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'field_tags' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:subject',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'rdftype' => array(
|
||||
0 => 'sioc:Item',
|
||||
1 => 'foaf:Document',
|
||||
),
|
||||
'title' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:title',
|
||||
),
|
||||
),
|
||||
'created' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:date',
|
||||
1 => 'dc:created',
|
||||
),
|
||||
'datatype' => 'xsd:dateTime',
|
||||
'callback' => 'date_iso8601',
|
||||
),
|
||||
'changed' => array(
|
||||
'predicates' => array(
|
||||
0 => 'dc:modified',
|
||||
),
|
||||
'datatype' => 'xsd:dateTime',
|
||||
'callback' => 'date_iso8601',
|
||||
),
|
||||
'body' => array(
|
||||
'predicates' => array(
|
||||
0 => 'content:encoded',
|
||||
),
|
||||
),
|
||||
'uid' => array(
|
||||
'predicates' => array(
|
||||
0 => 'sioc:has_creator',
|
||||
),
|
||||
'type' => 'rel',
|
||||
),
|
||||
'name' => array(
|
||||
'predicates' => array(
|
||||
0 => 'foaf:name',
|
||||
),
|
||||
),
|
||||
'comment_count' => array(
|
||||
'predicates' => array(
|
||||
0 => 'sioc:num_replies',
|
||||
),
|
||||
'datatype' => 'xsd:integer',
|
||||
),
|
||||
'last_activity' => array(
|
||||
'predicates' => array(
|
||||
0 => 'sioc:last_activity_date',
|
||||
),
|
||||
'datatype' => 'xsd:dateTime',
|
||||
'callback' => 'date_iso8601',
|
||||
),
|
||||
),
|
||||
'status' => '1',
|
||||
'sticky' => '0',
|
||||
'title' => 'Nunc sollicitudin',
|
||||
'tnid' => '0',
|
||||
'translate' => '0',
|
||||
'type' => 'article',
|
||||
'uid' => '7cf875e6-dc15-4404-f190-5a7c3e91d14c',
|
||||
'uuid' => '5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837',
|
||||
);
|
||||
|
||||
return $entities;
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
core = "7.x"
|
||||
dependencies[] = "entity"
|
||||
dependencies[] = "features"
|
||||
dependencies[] = "uuid"
|
||||
description = "Example feature mainly used for testing."
|
||||
features[uuid_entities][] = "deploy_example_plan"
|
||||
name = "UUID default entities example"
|
||||
package = "Features"
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-03
|
||||
version = "7.x-1.0-alpha3+52-dev"
|
||||
core = "7.x"
|
||||
project = "uuid"
|
||||
datestamp = "1359858369"
|
||||
|
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
// Drupal needs this blank file.
|
@@ -5,9 +5,8 @@ package = UUID
|
||||
dependencies[] = uuid
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-03
|
||||
version = "7.x-1.0-alpha3+52-dev"
|
||||
; Information added by Drupal.org packaging script on 2018-07-19
|
||||
version = "7.x-1.2"
|
||||
core = "7.x"
|
||||
project = "uuid"
|
||||
datestamp = "1359858369"
|
||||
|
||||
datestamp = "1531990689"
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* UUID path module functions.
|
||||
* UUID path module functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ function uuid_path_entity_uuid_save(&$entity, $entity_type) {
|
||||
*/
|
||||
function _uuid_path_load_url_aliases(&$entities, $entity_type) {
|
||||
$info = entity_get_info($entity_type);
|
||||
// we only care about entities with URLs.
|
||||
// We only care about entities with URLs.
|
||||
if (!isset($info['uri callback'])) {
|
||||
return;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ function _uuid_path_load_url_aliases(&$entities, $entity_type) {
|
||||
$aliases = _uuid_path_url_alias_load($path['path']);
|
||||
|
||||
// Ignore local IDs.
|
||||
foreach($aliases as &$alias) {
|
||||
foreach ($aliases as &$alias) {
|
||||
unset($alias->pid);
|
||||
unset($alias->source);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ function _uuid_path_load_url_aliases(&$entities, $entity_type) {
|
||||
function _uuid_path_save_url_aliases(&$entity, $entity_type) {
|
||||
$info = entity_get_info($entity_type);
|
||||
|
||||
// We only care when there is a url callback
|
||||
// We only care when there is a url callback.
|
||||
if (!isset($info['uri callback'])) {
|
||||
return FALSE;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ function _uuid_path_save_url_aliases(&$entity, $entity_type) {
|
||||
path_delete(array('source' => $path));
|
||||
|
||||
// Continue if aliases are present.
|
||||
if(empty($entity->url_alias)) {
|
||||
if (empty($entity->url_alias)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -77,10 +77,10 @@ function _uuid_path_save_url_aliases(&$entity, $entity_type) {
|
||||
/**
|
||||
* Loads all aliases associated with a path.
|
||||
*
|
||||
* @param $path
|
||||
* @param string $path
|
||||
* The source path to look up.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* Array of paths or NULL if none found.
|
||||
*/
|
||||
function _uuid_path_url_alias_load($path) {
|
||||
@@ -90,4 +90,3 @@ function _uuid_path_url_alias_load($path) {
|
||||
->execute()
|
||||
->fetchAll(PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
|
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
function _field_collection_resource_definition() {
|
||||
if (module_exists('field_collection')) {
|
||||
// We will allow uuid_services_services_resources_alter() to add the
|
||||
// default UUID-related operations to this resource.
|
||||
return array('field_collection_item' => array());
|
||||
}
|
||||
else {
|
||||
return array();
|
||||
}
|
||||
}
|
30
sites/all/modules/uuid/uuid_services/uuid_services.admin.inc
Normal file
30
sites/all/modules/uuid/uuid_services/uuid_services.admin.inc
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administration functions for UUID Service module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Settings form for UUID Services.
|
||||
*
|
||||
* @return array
|
||||
* Configuration form structure.
|
||||
*/
|
||||
function uuid_services_settings() {
|
||||
$form['uuid_services_support_all_entity_types'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Support all UUID entity types'),
|
||||
'#description' => t('Check this box to automatically provide Services integration for all entity types with UUID support.'),
|
||||
'#default_value' => variable_get('uuid_services_support_all_entity_types', FALSE),
|
||||
);
|
||||
$form['uuid_services_allowed_media_mimes'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Allowed Media Mime type'),
|
||||
'#default_value' => variable_get('uuid_services_allowed_media_mimes', UUID_SERVICES_DEFAULT_ALLOWED_MEDIA_MIMES),
|
||||
'#cols' => 40,
|
||||
'#rows' => 5,
|
||||
'#description' => t("Enter one mime type per line you wish to allow in the system without extension. Example mime type '<em>video/brightcove</em>'."),
|
||||
);
|
||||
return system_settings_form($form);
|
||||
}
|
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test the UUID File Services integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test the UUID File Services integration.
|
||||
*/
|
||||
class UuidFileServicesTest extends ServicesWebTestCase {
|
||||
|
||||
protected $priviledgedUser = NULL;
|
||||
|
||||
protected $endpoint = NULL;
|
||||
|
||||
/**
|
||||
* Implementation of getInfo().
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'UUID File Services tests',
|
||||
'description' => 'Test the file services resource UUID methods and actions.',
|
||||
'group' => 'UUID',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of setUp().
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp(
|
||||
'ctools',
|
||||
'services',
|
||||
'rest_server',
|
||||
'uuid_services',
|
||||
'entity',
|
||||
'file',
|
||||
'field',
|
||||
'file_entity'
|
||||
);
|
||||
$this->endpoint = $this->saveNewEndpoint();
|
||||
|
||||
variable_set('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function saveNewEndpoint() {
|
||||
$edit = $this->populateEndpointFAPI();
|
||||
$endpoint = new stdClass();
|
||||
$endpoint->disabled = FALSE;
|
||||
$endpoint->api_version = 3;
|
||||
$endpoint->name = $edit['name'];
|
||||
$endpoint->server = $edit['server'];
|
||||
$endpoint->path = $edit['path'];
|
||||
$endpoint->authentication = array(
|
||||
'services' => 'services',
|
||||
);
|
||||
$endpoint->server_settings = array(
|
||||
'formatters' => array(
|
||||
'json' => TRUE,
|
||||
'bencode' => TRUE,
|
||||
'rss' => TRUE,
|
||||
'plist' => TRUE,
|
||||
'xmlplist' => TRUE,
|
||||
'php' => TRUE,
|
||||
'yaml' => TRUE,
|
||||
'jsonp' => FALSE,
|
||||
'xml' => FALSE,
|
||||
),
|
||||
'parsers' => array(
|
||||
'application/x-yaml' => TRUE,
|
||||
'application/json' => TRUE,
|
||||
'application/vnd.php.serialized' => TRUE,
|
||||
'application/plist' => TRUE,
|
||||
'application/plist+xml' => TRUE,
|
||||
'application/x-www-form-urlencoded' => TRUE,
|
||||
'multipart/form-data' => TRUE,
|
||||
),
|
||||
);
|
||||
$endpoint->resources = array(
|
||||
'file' => array(
|
||||
'operations' => array(
|
||||
'retrieve' => array(
|
||||
'enabled' => '1',
|
||||
),
|
||||
'delete' => array(
|
||||
'enabled' => '1',
|
||||
),
|
||||
'index' => array(
|
||||
'enabled' => '1',
|
||||
),
|
||||
'update' => array(
|
||||
'enabled' => '1',
|
||||
),
|
||||
),
|
||||
'actions' => array(
|
||||
'create_raw' => array(
|
||||
'enabled' => '1',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$endpoint->debug = 1;
|
||||
$endpoint->export_type = FALSE;
|
||||
services_endpoint_save($endpoint);
|
||||
$endpoint = services_endpoint_load($endpoint->name);
|
||||
$this->assertTrue($endpoint->name == $edit['name'], 'Endpoint successfully created');
|
||||
return $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests file creation.
|
||||
*/
|
||||
public function testFileUpdate() {
|
||||
$this->privilegedUser = $this->drupalCreateUser(array('create files'));
|
||||
$this->drupalLogin($this->privilegedUser);
|
||||
|
||||
// Get a test file.
|
||||
$testfiles = $this->drupalGetTestFiles('php');
|
||||
$testfile = current($testfiles);
|
||||
|
||||
// Setup file to be created.
|
||||
$filepath = file_default_scheme() . '://' . rand() . '/' . rand() . '/' . $testfile->filename;
|
||||
$file_data = array(
|
||||
'uid' => '0',
|
||||
'filesize' => filesize($testfile->uri),
|
||||
'filename' => $testfile->filename,
|
||||
'filepath' => $filepath,
|
||||
'file' => base64_encode(file_get_contents($testfile->uri)),
|
||||
'uuid' => 'ee26fe5d-f781-4a38-bfe0-8bb350b90073',
|
||||
'type' => 'image',
|
||||
'filemime' => 'text/plain',
|
||||
'uri' => $testfile->uri,
|
||||
);
|
||||
|
||||
$response = $this->servicesPut($this->endpoint->path . '/file/create', $file_data);
|
||||
|
||||
// Get the saved file's extension.
|
||||
$file = file_load($response['body']->fid);
|
||||
$name = explode('.', $file->filename);
|
||||
$last = array_pop($name);
|
||||
$extension = strtolower($last);
|
||||
|
||||
$this->assertNotEqual('php', $extension, 'File was not created with a "php" extension.', 'UUID: File Create');
|
||||
}
|
||||
|
||||
}
|
@@ -7,9 +7,14 @@ dependencies[] = services
|
||||
dependencies[] = uuid
|
||||
dependencies[] = entity
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-03
|
||||
version = "7.x-1.0-alpha3+52-dev"
|
||||
test_dependencies[] = services
|
||||
test_dependencies[] = entity
|
||||
test_dependencies[] = file
|
||||
test_dependencies[] = field
|
||||
test_dependencies[] = file_entity
|
||||
|
||||
; Information added by Drupal.org packaging script on 2018-07-19
|
||||
version = "7.x-1.2"
|
||||
core = "7.x"
|
||||
project = "uuid"
|
||||
datestamp = "1359858369"
|
||||
|
||||
datestamp = "1531990689"
|
||||
|
14
sites/all/modules/uuid/uuid_services/uuid_services.install
Normal file
14
sites/all/modules/uuid/uuid_services/uuid_services.install
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* UUID module installation functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function uuid_services_uninstall() {
|
||||
variable_del('uuid_services_support_all_entity_types');
|
||||
variable_del('uuid_services_allowed_media_mimes');
|
||||
}
|
@@ -1,5 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* UUID Services module functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines defaults for UUID_SERVICES_ALLOWED_MEDIA_MIMES.
|
||||
*/
|
||||
define('UUID_SERVICES_DEFAULT_ALLOWED_MEDIA_MIMES',
|
||||
'video/brightcove
|
||||
video/youtube'
|
||||
);
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function uuid_services_menu() {
|
||||
$items['admin/config/services/uuid-services'] = array(
|
||||
'title' => 'UUID Services',
|
||||
'description' => 'Configure settings for UUID Services.',
|
||||
'access arguments' => array('administer services'),
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('uuid_services_settings'),
|
||||
'file' => 'uuid_services.admin.inc',
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_services_resources_alter().
|
||||
*
|
||||
@@ -14,7 +42,7 @@
|
||||
*/
|
||||
function uuid_services_services_resources_alter(&$resources, &$endpoint) {
|
||||
foreach (entity_get_info() as $entity_type => $entity_info) {
|
||||
if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE && isset($resources[$entity_type])) {
|
||||
if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE && (isset($resources[$entity_type]) || variable_get('uuid_services_support_all_entity_types', FALSE))) {
|
||||
unset($resources[$entity_type]['operations']['create']);
|
||||
|
||||
// Alter 'retrieve' method to use UUID enabled functions and arguments.
|
||||
@@ -126,6 +154,22 @@ function _uuid_services_entity_update($entity_type, $uuid, $entity) {
|
||||
else {
|
||||
$entity = (object) $entity;
|
||||
}
|
||||
$entity->uuid_services = TRUE;
|
||||
// Check that the mime type is whitelisted.
|
||||
$valid_media_mimes = variable_get('uuid_services_allowed_media_mimes', UUID_SERVICES_DEFAULT_ALLOWED_MEDIA_MIMES);
|
||||
|
||||
// Sanitize file user input.
|
||||
if ($entity_type == 'file') {
|
||||
// We have to make sure to whitelist mime types, to avoid the video files
|
||||
// getting converted into text files, when deployed from one env to other.
|
||||
if (!in_array($entity->filemime, preg_split('/\r?\n/', $valid_media_mimes))) {
|
||||
$entity->filename = _services_file_check_name_extension($entity->filename);
|
||||
$entity->uri = _services_file_check_destination_uri($entity->uri);
|
||||
if (!empty($entity->filepath)) {
|
||||
$entity->filepath = _services_file_check_destination($entity->filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
entity_uuid_save($entity_type, $entity);
|
||||
return $entity;
|
||||
}
|
||||
@@ -142,7 +186,15 @@ function _uuid_services_entity_update($entity_type, $uuid, $entity) {
|
||||
*/
|
||||
function _uuid_services_entity_delete($entity_type, $uuid) {
|
||||
try {
|
||||
$return = entity_uuid_delete($entity_type, array($uuid));
|
||||
$uuid_exist = (bool) entity_get_id_by_uuid($entity_type, array($uuid));
|
||||
if (!$uuid_exist) {
|
||||
/* UUID not found. Don't try to delete something that doesn't exist. */
|
||||
$args = array('@uuid' => $uuid, '@type' => $entity_type);
|
||||
watchdog('uuid_services', 'UUID @uuid not found for entity type @type', $args, WATCHDOG_WARNING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$return = entity_uuid_delete($entity_type, array($uuid)) !== FALSE;
|
||||
return $return;
|
||||
}
|
||||
catch (Exception $exception) {
|
||||
@@ -154,14 +206,14 @@ function _uuid_services_entity_delete($entity_type, $uuid) {
|
||||
/**
|
||||
* Access callback.
|
||||
*
|
||||
* @param $op
|
||||
* @param string $op
|
||||
* The operation we are trying to do on the entity. Can only be:
|
||||
* - "view"
|
||||
* - "update"
|
||||
* - "delete"
|
||||
* See 'uuid_services_services_resources_alter()' for an explanation why
|
||||
* 'create' is missing.
|
||||
* @param $args
|
||||
* @param array $args
|
||||
* The arguments passed to the method. The keys are holding the following:
|
||||
* 0. <entity_type>
|
||||
* 1. <uuid>
|
||||
@@ -182,7 +234,7 @@ function _uuid_services_entity_access($op, $args) {
|
||||
entity_make_entity_local($entity_type, $entity);
|
||||
}
|
||||
// Fetch the local entity if we've got an id.
|
||||
elseif (!empty($entity_id)) {
|
||||
elseif (!empty($entity_ids)) {
|
||||
$entities = entity_load($entity_type, $entity_ids);
|
||||
$entity = reset($entities);
|
||||
}
|
||||
@@ -192,10 +244,9 @@ function _uuid_services_entity_access($op, $args) {
|
||||
if ($op == 'update' && empty($entity_ids)) {
|
||||
$op = 'create';
|
||||
}
|
||||
// Taxonomy and Comment module uses 'edit' instead of 'update'.
|
||||
// Oh, how I love Drupal consistency.
|
||||
if (($entity_type == 'taxonomy_term' || $entity_type == 'comment') && $op == 'update') {
|
||||
$op = 'edit';
|
||||
// If the user doesn't exist return 406 like services does.
|
||||
if (($entity_type == 'user' && empty($entity) && $op == 'view')) {
|
||||
return services_error(t('There is no user with UUID @uuid.', array('@uuid' => $args[1])), 406);;
|
||||
}
|
||||
// The following code is taken from entity_access() with some extra logic
|
||||
// to handle the case where an entity type is not defining an access
|
||||
@@ -211,18 +262,3 @@ function _uuid_services_entity_access($op, $args) {
|
||||
return services_error($exception, 406, $entity_type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_services_resources().
|
||||
*/
|
||||
function uuid_services_services_resources() {
|
||||
module_load_include('inc', 'uuid_services', 'resources/field_collection.resource');
|
||||
|
||||
$resources = array(
|
||||
'#api_version' => 3002,
|
||||
);
|
||||
|
||||
$resources += _field_collection_resource_definition();
|
||||
|
||||
return $resources;
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* uuid_services_example.features.inc
|
||||
|
@@ -1,17 +1,18 @@
|
||||
core = "7.x"
|
||||
dependencies[] = "rest_server"
|
||||
dependencies[] = "services"
|
||||
dependencies[] = "uuid"
|
||||
dependencies[] = "uuid_services"
|
||||
description = "Example feature of a UUID service. Works well with the Deploy Example feature as a client."
|
||||
features[ctools][] = "services:services:3"
|
||||
features[services_endpoint][] = "uuid_services_example"
|
||||
name = "UUID Services Example"
|
||||
package = "Features"
|
||||
name = UUID Services Example
|
||||
description = Example feature of a UUID service. Works well with the Deploy Example feature as a client.
|
||||
core = 7.x
|
||||
package = Features
|
||||
php = 5.2.4
|
||||
dependencies[] = rest_server
|
||||
dependencies[] = services
|
||||
dependencies[] = uuid
|
||||
dependencies[] = uuid_services
|
||||
features[ctools][] = services:services:3
|
||||
features[features_api][] = api:2
|
||||
features[services_endpoint][] = uuid_services_example
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-03
|
||||
version = "7.x-1.0-alpha3+52-dev"
|
||||
; Information added by Drupal.org packaging script on 2018-07-19
|
||||
version = "7.x-1.2"
|
||||
core = "7.x"
|
||||
project = "uuid"
|
||||
datestamp = "1359858369"
|
||||
|
||||
datestamp = "1531990689"
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Code for the UUID Services Example feature.
|
||||
*/
|
||||
|
||||
include_once('uuid_services_example.features.inc');
|
||||
include_once 'uuid_services_example.features.inc';
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* uuid_services_example.services.inc
|
||||
@@ -10,7 +11,7 @@
|
||||
function uuid_services_example_default_services_endpoint() {
|
||||
$export = array();
|
||||
|
||||
$endpoint = new stdClass;
|
||||
$endpoint = new stdClass();
|
||||
$endpoint->disabled = FALSE; /* Edit this to true to make a default endpoint disabled initially */
|
||||
$endpoint->api_version = 3;
|
||||
$endpoint->name = 'uuid_services_example';
|
||||
@@ -25,7 +26,6 @@ function uuid_services_example_default_services_endpoint() {
|
||||
'bencode' => FALSE,
|
||||
'jsonp' => FALSE,
|
||||
'php' => FALSE,
|
||||
'rss' => FALSE,
|
||||
'xml' => FALSE,
|
||||
'yaml' => FALSE,
|
||||
),
|
||||
@@ -35,49 +35,61 @@ function uuid_services_example_default_services_endpoint() {
|
||||
'multipart/form-data' => TRUE,
|
||||
'application/vnd.php.serialized' => FALSE,
|
||||
'application/x-yaml' => FALSE,
|
||||
'application/xml' => FALSE,
|
||||
'text/xml' => FALSE,
|
||||
),
|
||||
);
|
||||
$endpoint->resources = array(
|
||||
'comment' => array(
|
||||
'operations' => array(
|
||||
'update' => array(
|
||||
'enabled' => 1,
|
||||
'enabled' => '1',
|
||||
),
|
||||
),
|
||||
),
|
||||
'file' => array(
|
||||
'operations' => array(
|
||||
'update' => array(
|
||||
'enabled' => 1,
|
||||
'enabled' => '1',
|
||||
),
|
||||
),
|
||||
),
|
||||
'node' => array(
|
||||
'operations' => array(
|
||||
'update' => array(
|
||||
'enabled' => 1,
|
||||
'enabled' => '1',
|
||||
),
|
||||
),
|
||||
),
|
||||
'taxonomy_term' => array(
|
||||
'operations' => array(
|
||||
'update' => array(
|
||||
'enabled' => 1,
|
||||
'enabled' => '1',
|
||||
),
|
||||
),
|
||||
),
|
||||
'user' => array(
|
||||
'operations' => array(
|
||||
'update' => array(
|
||||
'enabled' => 1,
|
||||
'enabled' => '1',
|
||||
),
|
||||
),
|
||||
'actions' => array(
|
||||
'login' => array(
|
||||
'enabled' => 1,
|
||||
'enabled' => '1',
|
||||
'settings' => array(
|
||||
'services' => array(
|
||||
'resource_api_version' => '1.0',
|
||||
),
|
||||
),
|
||||
),
|
||||
'logout' => array(
|
||||
'enabled' => 1,
|
||||
'enabled' => '1',
|
||||
'settings' => array(
|
||||
'services' => array(
|
||||
'resource_api_version' => '1.0',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user