first import
This commit is contained in:
339
sites/all/modules/uuid_features/LICENSE.txt
Normal file
339
sites/all/modules/uuid_features/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
38
sites/all/modules/uuid_features/includes/modules/content.inc
Normal file
38
sites/all/modules/uuid_features/includes/modules/content.inc
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* uuid_node hooks on behalf of the content module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render_alter().
|
||||
*
|
||||
* For most CCK fields, it is enough to simply add the values from each db
|
||||
* column into a field array.
|
||||
*/
|
||||
function content_uuid_node_features_export_render_alter(&$export, $node, $module) {
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK text fields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
// Let field modules do their own thing if they want.
|
||||
if (!module_hook($field['module'], 'uuid_node_features_export_render_alter')) {
|
||||
$field_name = $field['field_name'];
|
||||
$export->$field_name = array();
|
||||
// If the content type has changed since the last export, this field
|
||||
// may not exist.
|
||||
if (isset($node->$field_name)) {
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $data) {
|
||||
$export->{$field_name}[$delta] = array();
|
||||
|
||||
// Save the value of each column.
|
||||
foreach ($field['columns'] as $column => $column_data) {
|
||||
$export->{$field_name}[$delta][$column] = $data[$column];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* uuid_node hooks on behalf of the filefield module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_alter().
|
||||
*/
|
||||
function filefield_uuid_node_features_export_alter(&$export, &$pipe, $node) {
|
||||
$types = content_types();
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK filefields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
if ($field['module'] == 'filefield') {
|
||||
$field_name = $field['field_name'];
|
||||
|
||||
// If the content type has changed since the last export, this field
|
||||
// may not exist.
|
||||
if (isset($node->$field_name)) {
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $data) {
|
||||
if (!empty($data['fid'])) {
|
||||
$uuid = uuid_get_uuid('files', 'fid', $data['fid']);
|
||||
// If the referenced file doesn't have a uuid, take this opportunity to
|
||||
// create one.
|
||||
if (empty($uuid)) {
|
||||
$uuid = uuid_set_uuid('files', 'fid', $data['fid']);
|
||||
}
|
||||
$pipe['uuid_file'][$uuid] = $uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render_alter().
|
||||
*/
|
||||
function filefield_uuid_node_features_export_render_alter(&$export, $node, $module) {
|
||||
$types = content_types();
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK filefields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
if ($field['module'] == 'filefield') {
|
||||
$field_name = $field['field_name'];
|
||||
$export->$field_name = array();
|
||||
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $data) {
|
||||
if (!empty($data['fid'])) {
|
||||
$export->{$field_name}[$delta] = array(
|
||||
'uuid' => uuid_get_uuid('files', 'fid', $data['fid']),
|
||||
'list' => $data['list'],
|
||||
'data' => $data['data'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_rebuild_alter().
|
||||
* Replace filefield uuid's with a field array suitable for node_save().
|
||||
*/
|
||||
function filefield_uuid_node_features_rebuild_alter(&$node, $module) {
|
||||
$types = content_types();
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK nodereference fields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
if ($field['module'] == 'filefield') {
|
||||
$field_name = $field['field_name'];
|
||||
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $data) {
|
||||
$fid = uuid_get_serial_id('files', 'fid', $data['uuid']);
|
||||
$file = field_file_load($fid);
|
||||
|
||||
$node->{$field_name}[$delta] = $file + $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* uuid_node hooks on behalf of the nodereference module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render().
|
||||
*/
|
||||
function nodereference_uuid_node_features_export_alter(&$export, &$pipe, $node) {
|
||||
$types = content_types();
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK nodereference fields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
if ($field['module'] == 'nodereference') {
|
||||
$field_name = $field['field_name'];
|
||||
|
||||
// If the content type has changed since the last export, this field
|
||||
// may not exist.
|
||||
if (isset($node->$field_name)) {
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $data) {
|
||||
if (!empty($data['nid'])) {
|
||||
$uuid = uuid_get_uuid('node', 'nid', $data['nid']);
|
||||
// If the referenced node doesn't have a uuid, take this opportunity to
|
||||
// create one.
|
||||
if (empty($uuid)) {
|
||||
$uuid = uuid_set_uuid('node', 'nid', $data['nid']);
|
||||
}
|
||||
$pipe['uuid_node'][$uuid] = $uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render_alter().
|
||||
*/
|
||||
function nodereference_uuid_node_features_export_render_alter(&$export, $node, $module) {
|
||||
$types = content_types();
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK nodereference fields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
if ($field['module'] == 'nodereference') {
|
||||
$field_name = $field['field_name'];
|
||||
$export->$field_name = array();
|
||||
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $data) {
|
||||
if (!empty($data['nid'])) {
|
||||
$uuid = uuid_get_uuid('node', 'nid', $data['nid']);
|
||||
$export->{$field_name}[$delta] = $uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_rebuild_alter().
|
||||
* Replace noderef uuid's with a field array suitable for node_save().
|
||||
*/
|
||||
function nodereference_uuid_node_features_rebuild_alter(&$node, $module) {
|
||||
$types = content_types();
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK nodereference fields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
if ($field['module'] == 'nodereference') {
|
||||
$field_name = $field['field_name'];
|
||||
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $uuid) {
|
||||
$nid = uuid_get_serial_id('node', 'nid', $uuid);
|
||||
$node->{$field_name}[$delta] = array('nid' => $nid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* uuid_node hooks on behalf of the taxonomy module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render().
|
||||
*/
|
||||
function taxonomy_uuid_node_features_export_alter(&$export, &$pipe, $node) {
|
||||
if (!empty($node->taxonomy)) {
|
||||
foreach ($node->taxonomy as $term) {
|
||||
$vocabulary = taxonomy_vocabulary_load($term->vid);
|
||||
$voc_uuid = $vocabulary->machine_name;
|
||||
$pipe['uuid_vocabulary'][$voc_uuid] = $voc_uuid;
|
||||
|
||||
$term_uuid = $term->uuid;
|
||||
$pipe['uuid_term'][$term_uuid] = $term_uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render_alter().
|
||||
*/
|
||||
function taxonomy_uuid_node_features_export_render_alter(&$export, &$node, $module) {
|
||||
if (!empty($node->taxonomy)) {
|
||||
$export->uuid_term = array();
|
||||
foreach ($node->taxonomy as $term) {
|
||||
$export->uuid_term[] = $term->uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_rebuild_alter().
|
||||
* Build a taxonomy array suitable for node_save() from the uuid_term array.
|
||||
*/
|
||||
function taxonomy_uuid_node_features_rebuild_alter(&$node, $module) {
|
||||
if (!empty($node->uuid_term)) {
|
||||
$node->taxonomy = array();
|
||||
foreach ($node->uuid_term as $uuid) {
|
||||
$tid = uuid_taxonomy_term_find($uuid);
|
||||
if (empty($tid)) {
|
||||
// If no tid was found, then the term doesn't exist, and most likely
|
||||
// the uuid_term rebuild needs to run first.
|
||||
// TODO: figure out how to weight feature components.
|
||||
uuid_term_features_rebuild($module);
|
||||
|
||||
// Now try again.
|
||||
$tid = uuid_taxonomy_term_find($uuid);
|
||||
if (empty($tid)) {
|
||||
watchdog('uuid_features', 'The term specified by %uuid could not be found.', array('%uuid' => $uuid));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$node->taxonomy[] = $tid;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* uuid_node hooks on behalf of the userreference module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render().
|
||||
*/
|
||||
function userreference_uuid_node_features_export_render(&$export, &$pipe, $node) {
|
||||
// TODO: add user UUID's to pipe.
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uuid_node_features_export_render_alter().
|
||||
*/
|
||||
function userreference_uuid_node_features_export_render_alter(&$export, $node, $module) {
|
||||
$types = content_types();
|
||||
if (!empty($types[$node->type])) {
|
||||
// Find CCK userreference fields.
|
||||
foreach ($types[$node->type]['fields'] as $field) {
|
||||
if ($field['module'] == 'userreference') {
|
||||
$field_name = $field['field_name'];
|
||||
$export->$field_name = array();
|
||||
|
||||
// TODO: Use user UUID's instead.
|
||||
|
||||
// If the content type has changed since the last export, this field
|
||||
// may not exist.
|
||||
if (isset($node->$field_name)) {
|
||||
// Loop through all values of the field.
|
||||
foreach ($node->$field_name as $delta => $data) {
|
||||
$export->{$field_name}[$delta] = array();
|
||||
|
||||
// Save the value of each column.
|
||||
foreach ($field['columns'] as $column => $column_data) {
|
||||
$export->{$field_name}[$delta][$column] = $data[$column];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
107
sites/all/modules/uuid_features/includes/uuid_features.drush.inc
Normal file
107
sites/all/modules/uuid_features/includes/uuid_features.drush.inc
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* uuid_features module drush integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*
|
||||
* @See drush_parse_command() for a list of recognized keys.
|
||||
*
|
||||
* @return
|
||||
* An associative array describing your command(s).
|
||||
*/
|
||||
function uuid_features_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$items['uuid-features-update-files'] = array(
|
||||
'callback' => 'uuid_features_command_update_files',
|
||||
'description' => "Update files for features modules that use the uuid_file component.",
|
||||
'arguments' => array(
|
||||
'feature' => 'Feature name to export.',
|
||||
),
|
||||
'drupal dependencies' => array('features', 'uuid', 'uuid_features', 'filefield'),
|
||||
'aliases' => array('ufuf'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_drush_help().
|
||||
*/
|
||||
function uuid_features_drush_help($section) {
|
||||
switch ($section) {
|
||||
case 'drush:features':
|
||||
return dt("List all the available features for your site.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update files for features modules that use the uuid_file component.
|
||||
*/
|
||||
function uuid_features_command_update_files($feature = NULL) {
|
||||
if ($args = func_get_args()) {
|
||||
foreach ($args as $module) {
|
||||
if (($feature = feature_load($module, TRUE)) && module_exists($module)) {
|
||||
if (!empty($feature->info['features']['uuid_file'])) {
|
||||
$files = $feature->info['features']['uuid_file'];
|
||||
|
||||
$dest = drupal_get_path('module', $module) . '/uuid_file';
|
||||
file_prepare_directory($dest, FILE_CREATE_DIRECTORY);
|
||||
|
||||
foreach ($files as $uuid) {
|
||||
_uuid_features_drush_update_file($module, $uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($feature) {
|
||||
_features_drush_set_error($module, 'FEATURES_FEATURE_NOT_ENABLED');
|
||||
}
|
||||
else {
|
||||
_features_drush_set_error($module);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// By default just show contexts that are available.
|
||||
$rows = array(array(dt('Available features')));
|
||||
foreach (features_get_features(NULL, TRUE) as $name => $info) {
|
||||
$rows[] = array($name);
|
||||
}
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the file identified by $uuid into the feature specified by $module.
|
||||
*
|
||||
* @param string $module
|
||||
* @param string $uuid
|
||||
*/
|
||||
function _uuid_features_drush_update_file($module, $uuid) {
|
||||
$fid = uuid_get_serial_id('files', 'fid', $uuid);
|
||||
if (empty($fid) || !($file = field_file_load($fid))) {
|
||||
drush_set_error('UUID_FILE_NOT_FOUND', dt('The file specified by %uuid was not found.', array('%uuid' => $uuid)));
|
||||
}
|
||||
|
||||
$root = drush_get_option(array('r', 'root'), drush_locate_root());
|
||||
if ($root) {
|
||||
$directory = drupal_get_path('module', $module) . '/uuid_file';
|
||||
if (!is_dir($directory)) {
|
||||
drush_op('mkdir', $directory);
|
||||
}
|
||||
$source = $file['filepath'];
|
||||
$file_parts = explode('.', $file['filepath']);
|
||||
$extension = array_pop($file_parts);
|
||||
|
||||
$destination = $directory . '/' . $uuid . '.' . $extension;
|
||||
drush_op('copy', $source, $destination);
|
||||
drush_log(dt("Updated file: !uuid - !filename", array('!uuid' => $uuid, '!filename' => basename($destination))), 'ok');
|
||||
}
|
||||
else {
|
||||
drush_die(dt('Couldn\'t locate site root'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Features hooks for the uuid_file features component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_export().
|
||||
*/
|
||||
function uuid_file_features_export($data, &$export, $module_name = '') {
|
||||
$pipe = array();
|
||||
|
||||
$export['dependencies']['uuid_features'] = 'uuid_features';
|
||||
|
||||
foreach ($data as $uuid) {
|
||||
$export['features']['uuid_file'][$uuid] = $uuid;
|
||||
}
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_render().
|
||||
*/
|
||||
function uuid_file_features_export_render($module, $data) {
|
||||
$translatables = $code = array();
|
||||
|
||||
$code[] = ' $files = array();';
|
||||
$code[] = '';
|
||||
foreach ($data as $uuid) {
|
||||
$fid = uuid_get_serial_id('files', 'fid', $uuid);
|
||||
if (!$fid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file = field_file_load($fid);
|
||||
$file_parts = explode('.', $file['filepath']);
|
||||
$extension = array_pop($file_parts);
|
||||
|
||||
$export = array(
|
||||
'uuid' => $uuid,
|
||||
'hash' => md5_file($file['filepath']),
|
||||
'extension' => $extension,
|
||||
);
|
||||
|
||||
$code[] = ' $files[] = ' . features_var_export($export, ' ') . ';';
|
||||
}
|
||||
if (!empty($translatables)) {
|
||||
$code[] = features_translatables_export($translatables, ' ');
|
||||
}
|
||||
$code[] = ' return $files;';
|
||||
$code = implode("\n", $code);
|
||||
return array('uuid_features_default_files' => $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_revert().
|
||||
*/
|
||||
function uuid_file_features_revert($module) {
|
||||
uuid_file_features_rebuild($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_rebuild().
|
||||
* Rebuilds files based on UUID from code defaults.
|
||||
*/
|
||||
function uuid_file_features_rebuild($module) {
|
||||
$files = module_invoke($module, 'uuid_features_default_files');
|
||||
if (!empty($files)) {
|
||||
$source_dir = drupal_get_path('module', $module) . '/uuid_file';
|
||||
foreach ($files as $data) {
|
||||
$source = $source_dir . '/' . $data['uuid'] . '.' . $data['extension'];
|
||||
$data = file_get_contents($source);
|
||||
|
||||
// Copy the file and save to db.
|
||||
$file = file_save_data($data, NULL, FILE_EXISTS_REPLACE);
|
||||
}
|
||||
}
|
||||
}
|
150
sites/all/modules/uuid_features/includes/uuid_node.features.inc
Normal file
150
sites/all/modules/uuid_features/includes/uuid_node.features.inc
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Features hooks for the uuid_node features component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_options().
|
||||
*/
|
||||
function uuid_node_features_export_options() {
|
||||
$options = array();
|
||||
|
||||
$types = node_type_get_names();
|
||||
|
||||
$query = 'SELECT n.nid, n.title, n.type, n.uuid
|
||||
FROM {node} n ORDER BY n.type, n.title ASC';
|
||||
$results = db_query($query);
|
||||
foreach ($results as $node) {
|
||||
$options[$node->uuid] = t('@type: @title', array(
|
||||
'@type' => $types[$node->type],
|
||||
'@title' => $node->title,
|
||||
));
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export().
|
||||
*/
|
||||
function uuid_node_features_export($data, &$export, $module_name = '') {
|
||||
$pipe = array();
|
||||
|
||||
$export['dependencies']['uuid_features'] = 'uuid_features';
|
||||
|
||||
uuid_features_load_module_includes();
|
||||
|
||||
$nids = entity_get_id_by_uuid('node', $data);
|
||||
foreach ($nids as $uuid => $nid) {
|
||||
// Load the existing node, with a fresh cache.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
|
||||
$export['features']['uuid_node'][$uuid] = $uuid;
|
||||
$pipe['node'][$node->type] = $node->type;
|
||||
|
||||
// drupal_alter() normally supports just one byref parameter. Using
|
||||
// the __drupal_alter_by_ref key, we can store any additional parameters
|
||||
// that need to be altered, and they'll be split out into additional params
|
||||
// for the hook_*_alter() implementations. The hook_alter signature is
|
||||
// hook_uuid_node_features_export_alter(&$export, &$pipe, $node)
|
||||
$data = &$export;
|
||||
$data['__drupal_alter_by_ref'] = array(&$pipe);
|
||||
drupal_alter('uuid_node_features_export', $data, $node);
|
||||
}
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_render().
|
||||
*/
|
||||
function uuid_node_features_export_render($module, $data) {
|
||||
$translatables = $code = array();
|
||||
|
||||
uuid_features_load_module_includes();
|
||||
|
||||
$code[] = ' $nodes = array();';
|
||||
$code[] = '';
|
||||
$nids = entity_get_id_by_uuid('node', $data);
|
||||
foreach ($nids as $uuid => $nid) {
|
||||
// Only export the node if it exists.
|
||||
if ($nid === FALSE) {
|
||||
continue;
|
||||
}
|
||||
// Attempt to load the node, using a fresh cache.
|
||||
$node = node_load($nid, NULL, TRUE);
|
||||
if (empty($node)) {
|
||||
continue;
|
||||
}
|
||||
if (!empty($node->path)) {
|
||||
$node->pathauto_perform_alias = FALSE;
|
||||
}
|
||||
$export = $node;
|
||||
|
||||
// Use date instead of created, in the same format used by node_object_prepare.
|
||||
$export->date = format_date($export->created, 'custom', 'Y-m-d H:i:s O');
|
||||
|
||||
// Don't cause conflicts with nid/vid/revision_timestamp/changed fields.
|
||||
unset($export->nid);
|
||||
unset($export->vid);
|
||||
unset($export->revision_timestamp);
|
||||
unset($export->changed);
|
||||
unset($export->last_comment_timestamp);
|
||||
|
||||
// The hook_alter signature is:
|
||||
// hook_uuid_node_features_export_render_alter(&$export, $node, $module);
|
||||
drupal_alter('uuid_node_features_export_render', $export, $node, $module);
|
||||
|
||||
$code[] = ' $nodes[] = ' . features_var_export($export) . ';';
|
||||
}
|
||||
|
||||
if (!empty($translatables)) {
|
||||
$code[] = features_translatables_export($translatables, ' ');
|
||||
}
|
||||
|
||||
$code[] = ' return $nodes;';
|
||||
$code = implode("\n", $code);
|
||||
return array('uuid_features_default_content' => $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_revert().
|
||||
*/
|
||||
function uuid_node_features_revert($module) {
|
||||
uuid_node_features_rebuild($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_rebuild().
|
||||
* Rebuilds nodes based on UUID from code defaults.
|
||||
*/
|
||||
function uuid_node_features_rebuild($module) {
|
||||
$nodes = module_invoke($module, 'uuid_features_default_content');
|
||||
if (!empty($nodes)) {
|
||||
module_load_include('inc', 'node', 'node.pages');
|
||||
|
||||
foreach ($nodes as $data) {
|
||||
$node = (object) $data;
|
||||
node_object_prepare($node);
|
||||
|
||||
// Find the matching UUID, with a fresh cache.
|
||||
$nids = entity_get_id_by_uuid('node', array($node->uuid));
|
||||
if (isset($nids[$node->uuid])) {
|
||||
$nid = array_key_exists($node->uuid, $nids) ? $nids[$node->uuid] : FALSE;
|
||||
$existing = node_load($nid, NULL, TRUE);
|
||||
if (!empty($existing)) {
|
||||
$node->nid = $existing->nid;
|
||||
$node->vid = $existing->vid;
|
||||
}
|
||||
}
|
||||
|
||||
// The hook_alter signature is:
|
||||
// hook_uuid_node_features_rebuild_alter(&node, $module);
|
||||
drupal_alter('uuid_node_features_rebuild', $node, $module);
|
||||
|
||||
$node = node_submit($node);
|
||||
node_save($node);
|
||||
}
|
||||
}
|
||||
}
|
316
sites/all/modules/uuid_features/includes/uuid_term.features.inc
Normal file
316
sites/all/modules/uuid_features/includes/uuid_term.features.inc
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Features hooks for the uuid_term features component.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_options().
|
||||
*/
|
||||
function uuid_term_features_export_options() {
|
||||
$options = array();
|
||||
|
||||
$query = 'SELECT t.tid, t.name, v.name AS vname, t.uuid
|
||||
FROM {taxonomy_term_data} t
|
||||
INNER JOIN {taxonomy_vocabulary} v ON t.vid = v.vid
|
||||
ORDER BY v.name ASC, t.name ASC';
|
||||
$results = db_query($query);
|
||||
foreach ($results as $term) {
|
||||
$options[$term->uuid] = $term->vname . ' - ' . $term->name;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export().
|
||||
*/
|
||||
function uuid_term_features_export($data, &$export, $module_name = '') {
|
||||
$export['dependencies']['taxonomy'] = 'taxonomy';
|
||||
$export['dependencies']['uuid'] = 'uuid';
|
||||
$export['dependencies']['uuid_features'] = 'uuid_features';
|
||||
|
||||
foreach ($data as $uuid) {
|
||||
uuid_term_features_get_dependencies($export, $uuid);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds terms and its dependencies to the export.
|
||||
*
|
||||
* Parents and term references are handled recrusively, other references are not
|
||||
* yet supported.
|
||||
*/
|
||||
function uuid_term_features_get_dependencies(&$export, $uuid) {
|
||||
$terms = entity_uuid_load('taxonomy_term', array($uuid));
|
||||
if (count($terms)) {
|
||||
$term = reset($terms);
|
||||
$export['features']['uuid_term'][$uuid] = $uuid;
|
||||
$export['features']['taxonomy'][$term->vocabulary_machine_name] = $term->vocabulary_machine_name;
|
||||
// Recursively add all parents and the references of the parents.
|
||||
foreach (taxonomy_get_parents($term->tid) as $parent) {
|
||||
if (!in_array($parent->uuid, $export['features']['uuid_term'])) {
|
||||
uuid_term_features_get_dependencies($export, $parent->uuid);
|
||||
}
|
||||
}
|
||||
// Get term references.
|
||||
$instances = field_info_instances('taxonomy_term', $term->vocabulary_machine_name);
|
||||
foreach ($instances as $field_name => $instance) {
|
||||
$field = field_info_field($field_name);
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
if (isset($term->$field_name)) {
|
||||
foreach ($term->$field_name as $lang => $values) {
|
||||
foreach ($values as $value) {
|
||||
// $value['tid'] already contains the UUID.
|
||||
if (!in_array($value['tid'], $export['features']['uuid_term'])) {
|
||||
uuid_term_features_get_dependencies($export, $value['tid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_render().
|
||||
*/
|
||||
function uuid_term_features_export_render($module = 'foo', $data) {
|
||||
$translatables = $code = array();
|
||||
|
||||
$code[] = ' $terms = array();';
|
||||
$code[] = '';
|
||||
foreach ($data as $uuid) {
|
||||
// @todo reset = TRUE as otherwise references (parent, fields) were destroyed.
|
||||
$terms = entity_uuid_load('taxonomy_term', array($uuid), array(), TRUE);
|
||||
if (!count($terms)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Export the parent uuids.
|
||||
foreach ($terms as $term) {
|
||||
if($parents = taxonomy_get_parents($term->tid)) {
|
||||
foreach ($parents as $parent) {
|
||||
$term->parent[] = $parent->uuid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$export = reset($terms);
|
||||
|
||||
// Do not export ids.
|
||||
unset($export->vid);
|
||||
unset($export->tid);
|
||||
// No need to export the rdf mapping.
|
||||
unset($export->rdf_mapping);
|
||||
uuid_term_features_file_field_export($export);
|
||||
$code[] = ' $terms[] = ' . features_var_export($export, ' ') . ';';
|
||||
}
|
||||
|
||||
if (!empty($translatables)) {
|
||||
$code[] = features_translatables_export($translatables, ' ');
|
||||
}
|
||||
// Configuration settings need to be exported along with terms to
|
||||
// avoid diffs between the default and normal code returned by
|
||||
// this function.
|
||||
$code[] = ' variable_set(\'uuid_features_file_types\', ' . features_var_export(variable_get('uuid_features_file_types', array())) . ');';
|
||||
$code[] = ' variable_set(\'uuid_features_file_mode\', ' . features_var_export(variable_get('uuid_features_file_mode', 'inline')) . ');';
|
||||
$code[] = ' variable_set(\'uuid_features_file_assets_path\', ' . features_var_export(variable_get('uuid_features_file_assets_path', '')) . ');';
|
||||
$code[] = ' variable_set(\'uuid_features_file_supported_fields\', ' . features_var_export(variable_get('uuid_features_file_supported_fields', 'file, image')) . ');';
|
||||
$code[] = ' return $terms;';
|
||||
$code = implode("\n", $code);
|
||||
return array('uuid_features_default_terms' => $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_revert().
|
||||
*/
|
||||
function uuid_term_features_revert($module) {
|
||||
uuid_term_features_rebuild($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_rebuild().
|
||||
* Rebuilds terms based on UUID from code defaults.
|
||||
*/
|
||||
function uuid_term_features_rebuild($module) {
|
||||
// Import the vocabularies first.
|
||||
taxonomy_features_rebuild($module);
|
||||
field_features_rebuild($module);
|
||||
|
||||
$terms = module_invoke($module, 'uuid_features_default_terms');
|
||||
if (!empty($terms)) {
|
||||
// Verify that term objects is saved before any references are resolved.
|
||||
foreach ($terms as $data) {
|
||||
$existing = entity_get_id_by_uuid('taxonomy_term', array($data['uuid']));
|
||||
if (!count($existing)) {
|
||||
$voc = taxonomy_vocabulary_machine_name_load($data['vocabulary_machine_name']);
|
||||
// Only save the term, if the corresponding vocabulary already exisits.
|
||||
if ($voc) {
|
||||
$term = new stdClass;
|
||||
$term->uuid = $data['uuid'];
|
||||
$term->vid = $voc->vid;
|
||||
$term->name = $data['name'];
|
||||
taxonomy_term_save($term);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Save all other data and resolve references.
|
||||
foreach ($terms as $data) {
|
||||
$term = (object) $data;
|
||||
$voc = taxonomy_vocabulary_machine_name_load($term->vocabulary_machine_name);
|
||||
if ($voc) {
|
||||
$term->vid = $voc->vid;
|
||||
uuid_term_features_file_field_import($term, $voc);
|
||||
entity_uuid_save('taxonomy_term', $term);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle exporting file fields.
|
||||
*/
|
||||
function uuid_term_features_file_field_export(&$term) {
|
||||
$vocabularies = array_filter(variable_get('uuid_features_file_types', array()));
|
||||
if (in_array($term->vocabulary_machine_name, $vocabularies)) {
|
||||
$orig_assets_path = $assets_path = variable_get('uuid_features_file_assets_path', '');
|
||||
$export_mode = variable_get('uuid_features_file_mode', 'inline');
|
||||
|
||||
switch ($export_mode) {
|
||||
case 'local':
|
||||
$export_var = 'uuid_features_file_path';
|
||||
break;
|
||||
case 'remote':
|
||||
$export_var = 'uuid_features_file_url';
|
||||
break;
|
||||
default:
|
||||
case 'inline':
|
||||
$export_var = 'uuid_features_file_data';
|
||||
break;
|
||||
}
|
||||
// If files are supposed to be copied to the assets path.
|
||||
if ($export_mode == 'local' && $assets_path) {
|
||||
// Ensure the assets path is created
|
||||
if ((!is_dir($assets_path) && mkdir($assets_path, 0777, TRUE) == FALSE)
|
||||
|| !is_writable($assets_path)
|
||||
) {
|
||||
// Try creating a public path if the local path isn't writeable.
|
||||
// This is a kludgy solution to allow writing file assets to places
|
||||
// such as the profiles/myprofile directory, which isn't supposed to
|
||||
// be writeable
|
||||
$new_assets_path = 'public://' . $assets_path;
|
||||
if (!is_dir($new_assets_path) && mkdir($new_assets_path, 0777, TRUE) == FALSE) {
|
||||
drupal_set_message(t("Could not create assets path! '!path'", array('!path' => $assets_path)), 'error');
|
||||
// Don't continue if the assets path is not ready
|
||||
return;
|
||||
}
|
||||
$assets_path = $new_assets_path;
|
||||
}
|
||||
}
|
||||
|
||||
// get all fields from this vocabulary
|
||||
$fields = field_info_instances('taxonomy_term', $term->vocabulary_machine_name);
|
||||
foreach ($fields as $field_instance) {
|
||||
// load field infos to check the type
|
||||
$field = &$term->{$field_instance['field_name']};
|
||||
$info = field_info_field($field_instance['field_name']);
|
||||
|
||||
$supported_fields = array_map('trim', explode(',', variable_get('uuid_features_file_supported_fields', 'file, image')));
|
||||
|
||||
// check if this field should implement file import/export system
|
||||
if (in_array($info['type'], $supported_fields)) {
|
||||
|
||||
// we need to loop into each language because i18n translation can build
|
||||
// fields with different language than the node one.
|
||||
foreach($field as $language => $files) {
|
||||
if (is_array($files)) {
|
||||
foreach($files as $i => $file) {
|
||||
|
||||
// convert file to array to stay into the default uuid_features_file format
|
||||
$file = (object) $file;
|
||||
|
||||
// Check the file
|
||||
if (!isset($file->uri) || !is_file($file->uri)) {
|
||||
drupal_set_message(t("File field found on term, but file doesn't exist on disk? '!path'", array('!path' => $file->uri)), 'error');
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($export_mode == 'local') {
|
||||
if ($assets_path) {
|
||||
// The writeable path may be different from the path that gets saved
|
||||
// during the feature export to handle the public path/local path
|
||||
// dilemma mentioned above.
|
||||
$writeable_export_data = $assets_path . '/' . basename($file->uri);
|
||||
$export_data = $orig_assets_path . '/' . basename($file->uri);
|
||||
if (!copy($file->uri, $writeable_export_data)) {
|
||||
drupal_set_message(t("Export file error, could not copy '%filepath' to '%exportpath'.", array('%filepath' => $file->uri, '%exportpath' => $writeable_export_data)), 'error');
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$export_data = $file->uri;
|
||||
}
|
||||
}
|
||||
// Remote export mode
|
||||
elseif ($export_mode == 'remote') {
|
||||
$export_data = url($file->uri, array('absolute' => TRUE));
|
||||
}
|
||||
// Default is 'inline' export mode
|
||||
else {
|
||||
$export_data = base64_encode(file_get_contents($file->uri));
|
||||
}
|
||||
|
||||
// build the field again, and remove fid to be sure that imported node
|
||||
// will rebuild the file again, or keep an existing one with a different fid
|
||||
$field[$language][$i]['fid'] = NULL;
|
||||
$field[$language][$i]['timestamp'] = NULL;
|
||||
$field[$language][$i][$export_var] = $export_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle importing file fields.
|
||||
*/
|
||||
function uuid_term_features_file_field_import(&$term, $voc) {
|
||||
// Get all fields from this vocabulary.
|
||||
$fields = field_info_instances('taxonomy_term', $term->vocabulary_machine_name);
|
||||
|
||||
foreach($fields as $field_instance) {
|
||||
// Load field info to check the type.
|
||||
$field = &$term->{$field_instance['field_name']};
|
||||
$info = field_info_field($field_instance['field_name']);
|
||||
|
||||
$supported_fields = array_map('trim', explode(',', variable_get('uuid_features_file_supported_fields', 'file, image')));
|
||||
|
||||
// Check if this field should implement file import/export system.
|
||||
if (in_array($info['type'], $supported_fields)) {
|
||||
|
||||
// We need to loop into each language because i18n translation can build
|
||||
// fields with different language than the term one.
|
||||
foreach($field as $language => $files) {
|
||||
if (is_array($files)) {
|
||||
foreach($files as $i => $file) {
|
||||
|
||||
// Convert file to array to stay into the default uuid_features_file format.
|
||||
$file = (object)$file;
|
||||
|
||||
$result = _uuid_features_file_field_import_file($file);
|
||||
// The file was saved successfully, update the file field (by reference).
|
||||
if ($result == TRUE && isset($file->fid)) {
|
||||
$field[$language][$i] = (array)$file;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
sites/all/modules/uuid_features/uuid_features.info
Normal file
26
sites/all/modules/uuid_features/uuid_features.info
Normal file
@@ -0,0 +1,26 @@
|
||||
name = UUID Features
|
||||
description = Provides features integration for content (nodes, taxonomy, etc) based on the UUID module.
|
||||
core = 7.x
|
||||
dependencies[] = features
|
||||
dependencies[] = uuid
|
||||
dependencies[] = entity
|
||||
package = Features
|
||||
|
||||
files[] = uuid_features.install
|
||||
files[] = uuid_features.module
|
||||
files[] = includes/uuid_features.drush.inc
|
||||
files[] = includes/uuid_file.features.inc
|
||||
files[] = includes/uuid_node.features.inc
|
||||
files[] = includes/uuid_term.features.inc
|
||||
files[] = modules/content.inc
|
||||
files[] = modules/filefield.inc
|
||||
files[] = modules/nodereference.inc
|
||||
files[] = modules/taxonomy.inc
|
||||
files[] = modules/userreference.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-01
|
||||
version = "7.x-1.0-alpha3+2-dev"
|
||||
core = "7.x"
|
||||
project = "uuid_features"
|
||||
datestamp = "1359728333"
|
||||
|
19
sites/all/modules/uuid_features/uuid_features.install
Normal file
19
sites/all/modules/uuid_features/uuid_features.install
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the uuid_features module.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function uuid_features_enable() {
|
||||
db_update('system')
|
||||
->fields(array(
|
||||
'weight' => -50,
|
||||
))
|
||||
->condition('name', 'uuid_features')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
}
|
269
sites/all/modules/uuid_features/uuid_features.module
Normal file
269
sites/all/modules/uuid_features/uuid_features.module
Normal file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function uuid_features_menu() {
|
||||
$items['admin/config/content/uuid_features'] = array(
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('uuid_features_settings'),
|
||||
'title' => 'UUID Features Integration',
|
||||
'description' => 'Configure the settings for UUID Features Integration.',
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_api().
|
||||
*/
|
||||
function uuid_features_features_api() {
|
||||
$components = array();
|
||||
|
||||
$components['uuid_node'] = array(
|
||||
'name' => t('Content'),
|
||||
'feature_source' => TRUE,
|
||||
'default_hook' => 'uuid_features_default_content',
|
||||
'default_file' => FEATURES_DEFAULTS_INCLUDED,
|
||||
'file' => drupal_get_path('module', 'uuid_features') . '/includes/uuid_node.features.inc',
|
||||
);
|
||||
|
||||
if (module_exists('taxonomy')) {
|
||||
$components['uuid_term'] = array(
|
||||
'name' => t('Taxonomy Term'),
|
||||
'feature_source' => TRUE,
|
||||
'default_hook' => 'uuid_features_default_terms',
|
||||
'default_file' => FEATURES_DEFAULTS_INCLUDED,
|
||||
'file' => drupal_get_path('module', 'uuid_features') . '/includes/uuid_term.features.inc',
|
||||
);
|
||||
}
|
||||
|
||||
// Depends on http://drupal.org/node/808690
|
||||
if (function_exists('uuid_file_insert')) {
|
||||
$components['uuid_file'] = array(
|
||||
'name' => t('File'),
|
||||
'default_hook' => 'uuid_features_default_files',
|
||||
'default_file' => FEATURES_DEFAULTS_INCLUDED,
|
||||
'file' => drupal_get_path('module', 'uuid_features') . '/includes/uuid_file.features.inc',
|
||||
);
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all include files for enabled modules that this module provides
|
||||
* on-behalf-of functionality for.
|
||||
*/
|
||||
function uuid_features_load_module_includes() {
|
||||
static $loaded = FALSE;
|
||||
|
||||
if (!$loaded) {
|
||||
$inc_path = drupal_get_path('module', 'uuid_features') . '/includes/modules';
|
||||
foreach (module_list() as $module) {
|
||||
$file = "$inc_path/$module.inc";
|
||||
if (file_exists($file)) {
|
||||
include_once DRUPAL_ROOT . '/' . $file;
|
||||
}
|
||||
}
|
||||
$loaded = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_pipe_COMPONENT_alter().
|
||||
*
|
||||
* When exporting a vocabulary, include its terms.
|
||||
*/
|
||||
function uuid_features_features_pipe_taxonomy_alter($pipe, $data, $export) {
|
||||
if ($vocab = taxonomy_vocabulary_machine_name_load($data)) {
|
||||
foreach (taxonomy_get_tree($vocab->vid) as $term) {
|
||||
uuid_term_features_get_dependencies($export, $term->uuid);
|
||||
}
|
||||
$pipe['uuid_term'] = $export['features']['uuid_term'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback to configure module settings.
|
||||
*/
|
||||
function uuid_features_settings($form, &$form_state) {
|
||||
$vocabularies = array();
|
||||
foreach (taxonomy_vocabulary_get_names() as $machine_name => $properties) {
|
||||
$vocabularies[$machine_name] = $properties->name;
|
||||
}
|
||||
$form['file']['uuid_features_file_types'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Files exported for vocabularies'),
|
||||
'#default_value' => variable_get('uuid_features_file_types', array()),
|
||||
'#options' => $vocabularies,
|
||||
'#description' => t('Which vocabularies should export file fields?'),
|
||||
);
|
||||
|
||||
$form['file']['uuid_features_file_mode'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('File export mode'),
|
||||
'#default_value' => variable_get('uuid_features_file_mode', 'inline'),
|
||||
'#options' => array(
|
||||
'inline' => t('Inline Base64'),
|
||||
'local' => t('Local file export'),
|
||||
'remote' => t('Remote file export, URL')
|
||||
),
|
||||
'#description' => t('Should file exports be inline inside the export code, a local path to the file, or a URL? Inline Base64 is the easiest option to use but can sometimes exceed PHP post limits, local and remote modes are more useful for power users. <em>NOTE: Remote mode only works with a public files directory.</em>'),
|
||||
);
|
||||
|
||||
$form['file']['uuid_features_file_assets_path'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Local file field assets path'),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => variable_get('uuid_features_file_assets_path', ''),
|
||||
'#description' => t(
|
||||
'Optionally, copy files to this path when the node is exported.
|
||||
The primary advantage of this is to divert exported files into a
|
||||
safe location so they can be committed to source control (eg: SVN,
|
||||
CVS, Git). <em>Tip: For install profile developers, setting this
|
||||
path to <code>profiles/my_profile/uuid_features_assets</code> may be
|
||||
useful.</em>'
|
||||
),
|
||||
'#required' => FALSE,
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name=uuid_features_file_mode]' => array('value' => 'local'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$form['file']['uuid_features_file_supported_fields'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Supported file field types'),
|
||||
'#default_value' => variable_get('uuid_features_file_supported_fields', 'file, image'),
|
||||
'#maxlength' => 512,
|
||||
'#description' => t('Comma seperated list of file field types to detect for export/import.'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects remote and local file exports and imports accordingly.
|
||||
*
|
||||
* @param &$file
|
||||
* The file, passed by reference.
|
||||
* @return TRUE or FALSE
|
||||
* Depending on success or failure. On success the $file object will
|
||||
* have a valid $file->fid attribute.
|
||||
*/
|
||||
function _uuid_features_file_field_import_file(&$file) {
|
||||
// This is here for historical reasons to support older exports. It can be
|
||||
// removed in the next major version.
|
||||
$file->uri = strtr($file->uri, array('#FILES_DIRECTORY_PATH#' => 'public:/'));
|
||||
|
||||
// The file is already in the right location AND either the
|
||||
// uuid_features_file_path is not set or the uuid_features_file_path and filepath
|
||||
// contain the same file
|
||||
if (is_file($file->uri) &&
|
||||
(
|
||||
(!isset($file->uuid_features_file_path) || !is_file($file->uuid_features_file_path)) ||
|
||||
(
|
||||
is_file($file->uuid_features_file_path) &&
|
||||
filesize($file->uri) == filesize($file->uuid_features_file_path) &&
|
||||
strtoupper(dechex(crc32(file_get_contents($file->uri)))) ==
|
||||
strtoupper(dechex(crc32(file_get_contents($file->uuid_features_file_path))))
|
||||
)
|
||||
)
|
||||
) {
|
||||
// Keep existing file if it exists already at this uri (see also #1023254)
|
||||
// Issue #1058750.
|
||||
$query = db_select('file_managed', 'f')
|
||||
->fields('f', array('fid'))
|
||||
->condition('uri', $file->uri)
|
||||
->execute()
|
||||
->fetchCol();
|
||||
|
||||
if (!empty($query)) {
|
||||
watchdog('uuid_features', 'kept existing managed file at uri "%uri"', array('%uri' => $file->uri), WATCHDOG_NOTICE);
|
||||
$file = file_load(array_shift($query));
|
||||
}
|
||||
|
||||
$file = file_save($file);
|
||||
}
|
||||
elseif (isset($file->uuid_features_file_data)) {
|
||||
$directory = drupal_dirname($file->uri);
|
||||
if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
|
||||
if (file_put_contents($file->uri, base64_decode($file->uuid_features_file_data))) {
|
||||
$file = file_save($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
// The file is in a local location, move it to the
|
||||
// destination then finish the save
|
||||
elseif (isset($file->uuid_features_file_path) && is_file($file->uuid_features_file_path)) {
|
||||
$directory = drupal_dirname($file->uri);
|
||||
if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
|
||||
// The $file->uuid_features_file_path is passed to reference, and modified
|
||||
// by file_unmanaged_copy(). Making a copy to avoid tainting the original.
|
||||
$uuid_features_file_path = $file->uuid_features_file_path;
|
||||
file_unmanaged_copy($uuid_features_file_path, $directory, FILE_EXISTS_REPLACE);
|
||||
|
||||
// At this point the $file->uuid_features_file_path will contain the
|
||||
// destination of the copied file
|
||||
//$file->uri = $uuid_features_file_path;
|
||||
$file = file_save($file);
|
||||
}
|
||||
}
|
||||
// The file is in a remote location, attempt to download it
|
||||
elseif (isset($file->uuid_features_file_url)) {
|
||||
// Need time to do the download
|
||||
ini_set('max_execution_time', 900);
|
||||
|
||||
$temp_path = file_directory_temp() . '/' . md5(mt_rand()) . '.txt';
|
||||
if (($source = fopen($file->uuid_features_file_url, 'r')) == FALSE) {
|
||||
drupal_set_message(t("Could not open '@file' for reading.", array('@file' => $file->uuid_features_file_url)));
|
||||
return FALSE;
|
||||
}
|
||||
elseif (($dest = fopen($temp_path, 'w')) == FALSE) {
|
||||
drupal_set_message(t("Could not open '@file' for writing.", array('@file' => $file->uri)));
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
// PHP5 specific, downloads the file and does buffering
|
||||
// automatically.
|
||||
$bytes_read = @stream_copy_to_stream($source, $dest);
|
||||
|
||||
// Flush all buffers and wipe the file statistics cache
|
||||
@fflush($source);
|
||||
@fflush($dest);
|
||||
clearstatcache();
|
||||
|
||||
if ($bytes_read != filesize($temp_path)) {
|
||||
drupal_set_message(t("Remote export '!url' could not be fully downloaded, '@file' to temporary location '!temp'.", array('!url' => $file->uuid_features_file_url, '@file' => $file->uri, '!temp' => $temp_path)));
|
||||
return FALSE;
|
||||
}
|
||||
// File was downloaded successfully!
|
||||
else {
|
||||
if (!@copy($temp_path, $file->uri)) {
|
||||
unlink($temp_path);
|
||||
drupal_set_message(t("Could not move temporary file '@temp' to '@file'.", array('@temp' => $temp_path, '@file' => $file->uri)));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
unlink($temp_path);
|
||||
$file->filesize = filesize($file->uri);
|
||||
$file->filemime = file_get_mimetype($file->uri);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($source);
|
||||
fclose($dest);
|
||||
|
||||
$file = file_save($file);
|
||||
}
|
||||
// Unknown error
|
||||
else {
|
||||
drupal_set_message(t("Unknown error occurred attempting to import file: @filepath", array('@filepath' => $file->uri)), 'error');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
Reference in New Issue
Block a user