Révision e7101f36
Ajouté par Julien Enselme il y a environ 9 ans
drupal7/sites/all/modules/uuid/uuid.core.inc | ||
---|---|---|
125 | 125 |
function file_entity_uuid_presave(&$entity, $entity_type) { |
126 | 126 |
if ($entity_type == 'file') { |
127 | 127 |
entity_property_uuid_to_id($entity, 'user', 'uid'); |
128 |
|
|
129 |
// Write the new file to the local filesystem. |
|
128 | 130 |
if (isset($entity->file_contents)) { |
129 |
$directory = drupal_dirname($entity->uri); |
|
131 |
// Don't try to write it if it uses a stream wrapper that isn't writeable |
|
132 |
// (for example, if it is a remotely-hosted video). |
|
133 |
$scheme = file_uri_scheme($entity->uri); |
|
134 |
$wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_WRITE); |
|
135 |
if (empty($wrappers[$scheme])) { |
|
136 |
return; |
|
137 |
} |
|
138 |
|
|
139 |
// Check for an existing file with the same URI. |
|
140 |
$existing_files = file_load_multiple(array(), array('uri' => $entity->uri)); |
|
141 |
$existing = (object) array('uri' => NULL, 'uuid' => NULL); |
|
142 |
if (count($existing_files)) { |
|
143 |
$existing = reset($existing_files); |
|
144 |
} |
|
145 |
|
|
146 |
// If this is a new file and there is an existing file with the same URI, |
|
147 |
// but a different uuid then rename this file. |
|
148 |
if ($entity->is_new && $entity->uri == $existing->uri && $entity->uuid != $existing->uuid) { |
|
149 |
$uri = $entity->uri; |
|
150 |
$replace = FILE_EXISTS_RENAME; |
|
151 |
} |
|
152 |
// If this has an id, meaning UUID has already matched the uuid to an |
|
153 |
// existing file, but it has a URI that matches a file with a different |
|
154 |
// uuid, then load the file with the matching uuid and use the URI from |
|
155 |
// that file. The existing file with the matching uuid is most likely a |
|
156 |
// file that was previously renamed, e.g. as in the condition above, to |
|
157 |
// avoid conflict. The uuid matches because they are the same file, but |
|
158 |
// the URI does not because an incrementing number was added as part of |
|
159 |
// the renaming. |
|
160 |
elseif ($entity->uri == $existing->uri && $entity->uuid != $existing->uuid) { |
|
161 |
$file = file_load($entity->fid); |
|
162 |
$uri = $file->uri; |
|
163 |
$replace = FILE_EXISTS_REPLACE; |
|
164 |
} |
|
165 |
// Otherwise create a new file or replace the existing file contents. |
|
166 |
else { |
|
167 |
$uri = $entity->uri; |
|
168 |
$replace = FILE_EXISTS_REPLACE; |
|
169 |
} |
|
170 |
|
|
171 |
$directory = drupal_dirname($uri); |
|
130 | 172 |
file_prepare_directory($directory, FILE_CREATE_DIRECTORY); |
131 |
file_unmanaged_save_data(base64_decode($entity->file_contents), $entity->uri, FILE_EXISTS_REPLACE);
|
|
173 |
$entity->uri = file_unmanaged_save_data(base64_decode($entity->file_contents), $uri, $replace);
|
|
132 | 174 |
} |
133 | 175 |
} |
134 | 176 |
} |
... | ... | |
368 | 410 |
} |
369 | 411 |
|
370 | 412 |
/** |
371 |
* Implementation of hook_uuid_entities_features_export_entity_alter().
|
|
413 |
* Implementations hook_uuid_entities_features_export_entity_alter().
|
|
372 | 414 |
*/ |
373 | 415 |
function user_uuid_entities_features_export_entity_alter(&$entity, $entity_type) { |
374 | 416 |
if ($entity_type == 'user') { |
Formats disponibles : Unified diff
Update uuid 1.0-alpha5 1.0-alpha6