added migration modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-14 14:56:04 +01:00
parent 5a43b028b7
commit c546d42e72
183 changed files with 12883 additions and 0 deletions
@@ -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.
@@ -0,0 +1,87 @@
The migrate_upgrade module provides drush support for performing upgrades from
previous versions of Drupal to Drupal 8. It implements two drush commands:
* migrate-upgrade - performs a complete import of the source site's configuration
and content into the target Drupal 8 site. Optionally, with the --configure-only
flag, it may create migration configurations for such an import without actually
running them, to permit customization of the import process.
* migrate-upgrade-rollback - removes content and certain configuration
previously imported either by the migrate-upgrade command or by the core
upgrade UI.
migrate-upgrade
===============
The upgrade command requires a Drupal 6-style database URL of the source site's
database, and the location of the source site's public files.
drush migrate-upgrade --legacy-db-url=mysql://user:pw@127.0.0.1/d6db --legacy-root=http://example.com
The --legacy-root option may be either the domain of your existing Drupal site
(with the public files pulled by HTTP), or a local file directory into which you
have copied the files directory from your source site.
If your source site used a database prefix for all tables, you may specify the
prefix with --legacy-db-prefix. Migration from sites with partial or mixed
prefixing is not supported. Note that if the source site is stored in a Postgres
schema, you must set the prefix to the schema with a period appended (e.g.,
--legacy-db-prefix=drupal.).
The migrate-upgrade command, like the core upgrade UI, is designed to be run on
a freshly installed and empty Drupal 8 site (where the only site configuration
that has been done is enabling any modules for which you wish to migrate data).
migrate-upgrade-rollback
========================
The rollback command has no arguments or options:
drush migrate-upgrade-rollback
If it detects that an upgrade has been performed, either by migrate-upgrade or
by the core UI, it removes all content imported via the migration process (it
identifies the upgrade by the presence of the migrate_drupal_ui.performed state
key). In addition, any configuration entites created by the migration process
(such as content type and field definitions) are also removed. Because simple
configuration settings (such as the site title) are generally modified rather
than created by the upgrade process, and the original values are not preserved,
those changes are not rolled back. To completely return to the previous state,
you need to restore the site from backup, or reinstall a fresh empty site.
migrate-upgrade --configure-only
================================
At the time of this release, tools have not yet been developed (along the lines
of the migrate_d2d_ui module under Drupal 7) for customizing Drupal-to-Drupal
migrations in Drupal 8. For now, the best option short of doing custom
development is to use the --configure-only option on migrate-upgrade to replace
the actual execution of the migrations with export of their configuration to
configuration entities, which can then be modified as needed for a particular
migration scenario. A suggested workflow:
1. Install a fresh empty D8 site, enabling all modules for which you wish to
migrate data.
2. Run the drush migrate-upgrade command with the --configure-only option. This
generates migration configuration entities in the D8 database (config table).
3. Create a custom module containing only a .info.yml file (with dependencies on
migrate_plus and migrate_drupal) and a config/install directory.
4. Export your site configuration, e.g. drush cex --destination=/tmp/export
5. Copy the migration configuration that was generated by migrate-upgrade into
the custom module - be sure *not* to copy the default group configuration,
which is defined by migrate_plus:
cp /tmp/export/migrate_plus.migration.* /tmp/export/migrate_plus.migration_group.migrate_*.yml migrate_custom/config/install/
6. Look at that migrate_plus.migration_group.* file - you'll see your database
configuration captured there. In most cases, what you'll want to do is define
your database connection in settings.php with those credentials under the key
that is configured there - you won't want to commit the credentials to your
git repo.
7. Edit the generated .yml files to reflect your custom migration path.
8. Reinstall D8, enable your custom module and migrate_tools, and proceed to
work with your Drupal migrations as you would with any custom migration.
Hint: you'll probably want config_devel so you can edit .yml files in
config/install and immediately test your changes.
Note that the configuration entities generated above need to be prefixed to
avoid conflict with the core migration plugins they originated from. For
example, by default the core d6_user plugin generates the upgrade_d6_user
configuration entity. You may modify the 'upgrade_' prefix by providing a
--migration-prefix option.
@@ -0,0 +1,11 @@
{
"name": "drupal/migrate_upgrade",
"description": "Drush support for direct upgrades from older Drupal versions.",
"type": "drupal-module",
"require-dev": {
"drupal/coder": "^8"
},
"license": "GPL-2.0+",
"require": {},
"minimum-stability": "dev"
}
@@ -0,0 +1,93 @@
<?php
/**
* @file
* Command-line tools to aid performing and developing upgrade migrations.
*/
use Drupal\migrate_upgrade\MigrateUpgradeDrushRunner;
/**
* Implements hook_drush_command().
*/
function migrate_upgrade_drush_command() {
$items['migrate-upgrade'] = [
'description' => 'Perform one or more upgrade processes.',
'options' => [
'legacy-db-url' => 'A Drupal 6 style database URL. Required if you do not set legacy-db-key.',
'legacy-db-key' => 'A database connection key from settings.php. Use as an alternative to legacy-db-url',
'legacy-db-prefix' => 'Prefix of the legacy Drupal installation.',
'legacy-root' => 'Site address or root of the legacy Drupal installation',
'configure-only' => 'Set up the appropriate upgrade processes but do not perform them',
'migration-prefix' => 'With configure-only, a prefix to apply to generated migration ids. Defaults to \'upgrade_\'',
],
'examples' => [
'migrate-upgrade --legacy-db-url=\'mysql://root:pass@127.0.0.1/d6\'' => 'Upgrade a Drupal 6 database to Drupal 8',
'migrate-upgrade --legacy-db-key=\'drupal_7\'' => 'Upgrade Drupal 7 database where the connection to Drupal 7 has already been created in settings.php ($databases[\'drupal_7\'])',
'migrate-upgrade --legacy-db-url=\'mysql://root:pass@127.0.0.1/d7\' --configure-only --migration-prefix=d7_custom_' => 'Generate migrations for a custom migration from Drupal 7 to Drupal 8',
],
'drupal dependencies' => ['migrate_upgrade'],
];
$items['migrate-upgrade-rollback'] = [
'description' => 'Rolls back and removes upgrade migrations.',
'examples' => [
'migrate-upgrade-rollback' => 'Rolls back a previously-run upgrade',
],
'drupal dependencies' => ['migrate_upgrade'],
];
return $items;
}
/**
* Execute the upgrade command, configuring the necessary migrations and
* optionally perform the imports.
*/
function drush_migrate_upgrade() {
$runner = new MigrateUpgradeDrushRunner();
try {
$runner->configure();
if (drush_get_option('configure-only')) {
$runner->export();
}
else {
$runner->import();
\Drupal::state()->set('migrate_drupal_ui.performed', REQUEST_TIME);
}
// Remove the global database state.
\Drupal::state()->delete('migrate.fallback_state_key');
}
catch (\Exception $e) {
drush_log($e->getMessage(), 'error');
}
}
/**
* Rolls back any upgrade migrations that are present, and deletes the migrations
* themselves.
*/
function drush_migrate_upgrade_rollback() {
if ($date_performed = \Drupal::state()->get('migrate_drupal_ui.performed')) {
if (drush_confirm(dt('All migrations tagged as \'Drupal\' will be rolled back. Are you sure?'))) {
$runner = new MigrateUpgradeDrushRunner();
try {
drush_log(dt('Rolling back the upgrades performed @date',
['@date' => \Drupal::service('date.formatter')->format($date_performed)]));
$runner->rollback();
\Drupal::state()->delete('migrate_drupal_ui.performed');
drush_log(dt('Rolled back upgrades'));
}
catch (\Exception $e) {
drush_log($e->getMessage(), 'error');
}
}
else {
drush_user_abort();
}
}
else {
drush_log(dt('No upgrade operation has been performed.'), 'warning');
}
}
@@ -0,0 +1,16 @@
name: Drupal Upgrade
type: module
description: 'Drush support for direct upgrades from older Drupal versions.'
package: Migration
# core: 8.x
dependencies:
- drupal:migrate (>=8.2)
- drupal:migrate_drupal
- migrate_plus:migrate_plus
- drupal:dblog
# Information added by Drupal.org packaging script on 2017-09-02
version: '8.x-3.0-rc2'
core: '8.x'
project: 'migrate_upgrade'
datestamp: 1504384149
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="drupal_core">
<description>PHP CodeSniffer configuration</description>
<file>.</file>
<arg name="extensions" value="install,module,php"/>
<!--Exclude third party code.-->
<exclude-pattern>./vendor/*</exclude-pattern>
<!-- Only include specific sniffs that pass. This ensures that, if new sniffs are added, HEAD does not fail.-->
<!-- Drupal sniffs -->
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Classes/UseLeadingBackslashSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/CSS/ColourDefinitionSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php">
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php">
<!-- Sniff for these errors: SpacingAfterTagGroup, WrongEnd, SpacingBetween,
ContentAfterOpen, SpacingBeforeShort, TagValueIndent, ShortStartSpace,
SpacingAfter -->
<exclude name="Drupal.Commenting.DocComment.LongNotCapital"/>
<!-- ParamNotFirst still not decided for PHPUnit-based tests.
@see https://www.drupal.org/node/2253915 -->
<exclude name="Drupal.Commenting.DocComment.ParamNotFirst"/>
<exclude name="Drupal.Commenting.DocComment.SpacingBeforeTags"/>
<exclude name="Drupal.Commenting.DocComment.LongFullStop"/>
<exclude name="Drupal.Commenting.DocComment.ShortNotCapital"/>
<exclude name="Drupal.Commenting.DocComment.ShortFullStop"/>
<!-- TagsNotGrouped and ParamGroup have false-positives.
@see https://www.drupal.org/node/2060925 -->
<exclude name="Drupal.Commenting.DocComment.TagsNotGrouped"/>
<exclude name="Drupal.Commenting.DocComment.ParamGroup"/>
<exclude name="Drupal.Commenting.DocComment.ShortSingleLine"/>
<exclude name="Drupal.Commenting.DocComment.TagGroupSpacing"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FileCommentSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php">
<exclude name="Drupal.Commenting.FunctionComment.IncorrectTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidNoReturn"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidReturnNotVoid"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingFile"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamType"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnType"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamCommentFullStop"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamCommentIndentation"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamMissingDefinition"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamNameNoMatch"/>
<exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/ControlStructures/ElseIfSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/ControlStructures/ControlSignatureSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Files/EndFileNewlineSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Files/TxtFileLineLengthSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Formatting/MultiLineAssignmentSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Formatting/SpaceUnaryOperatorSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Functions/DiscouragedFunctionsSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php">
<!-- Sniff for: LowerStart -->
<exclude name="Drupal.NamingConventions.ValidVariableName.LowerCamelName"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/EmptyInstallSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php">
<exclude name="Drupal.Semantics.FunctionT.BackslashSingleQuote"/>
<exclude name="Drupal.Semantics.FunctionT.NotLiteralString"/>
<exclude name="Drupal.Semantics.FunctionT.ConcatString"/>
</rule>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/FunctionWatchdogSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/InstallHooksSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/LStringTranslatableSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/PregSecuritySniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/TInHookMenuSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/TInHookSchemaSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ObjectOperatorSpacingSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenTagNewlineSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/OperatorSpacingSniff.php"/>
<rule ref="vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php"/>
<!-- Drupal Practice sniffs -->
<rule ref="vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php"/>
<!-- Generic sniffs -->
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.NamingConventions.ConstructorName" />
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.UpperCaseConstant"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
<!-- PSR-2 sniffs -->
<rule ref="PSR2.Classes.PropertyDeclaration">
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
</rule>
<!-- Squiz sniffs -->
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1"/>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
</ruleset>
@@ -0,0 +1,23 @@
<?php
namespace Drupal\migrate_upgrade;
use Drupal\migrate\MigrateMessageInterface;
class DrushLogMigrateMessage implements MigrateMessageInterface {
/**
* Output a message from the migration.
*
* @param string $message
* The message to display.
* @param string $type
* The type of message to display.
*
* @see drush_log()
*/
public function display($message, $type = 'status') {
drush_log($message, $type);
}
}
@@ -0,0 +1,324 @@
<?php
namespace Drupal\migrate_upgrade;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\Event\MigrateIdMapMessageEvent;
use Drupal\migrate\MigrateExecutable;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\migrate_drupal\MigrationConfigurationTrait;
use Drupal\migrate_plus\Entity\Migration;
use Drupal\migrate_plus\Entity\MigrationGroup;
use Drupal\Core\Database\Database;
class MigrateUpgradeDrushRunner {
use MigrationConfigurationTrait;
use StringTranslationTrait;
/**
* The list of migrations to run and their configuration.
*
* @var \Drupal\migrate\Plugin\Migration[]
*/
protected $migrationList;
/**
* MigrateMessage instance to display messages during the migration process.
*
* @var \Drupal\migrate_upgrade\DrushLogMigrateMessage
*/
protected static $messages;
/**
* The Drupal version being imported.
*
* @var string
*/
protected $version;
/**
* The state key used to store database configuration.
*
* @var string
*/
protected $databaseStateKey;
/**
* List of D6 node migration IDs we've seen.
*
* @var array
*/
protected $nodeMigrations = [];
/**
* List of process plugin IDs used to lookup migrations.
*
* @var array
*/
protected $migrationLookupPluginIds = [
'migration',
'migration_lookup',
];
/**
* From the provided source information, instantiate the appropriate migrations
* in the active configuration.
*
* @throws \Exception
*/
public function configure() {
$legacy_db_key = drush_get_option('legacy-db-key');
if (!empty($legacy_db_key)) {
$connection = Database::getConnection('default', drush_get_option('legacy-db-key'));
$this->version = $this->getLegacyDrupalVersion($connection);
$database_state['key'] = drush_get_option('legacy-db-key');
$database_state_key = 'migrate_drupal_' . $this->version;
\Drupal::state()->set($database_state_key, $database_state);
\Drupal::state()->set('migrate.fallback_state_key', $database_state_key);
}
else {
$db_url = drush_get_option('legacy-db-url');
$db_spec = drush_convert_db_from_db_url($db_url);
$db_prefix = drush_get_option('legacy-db-prefix');
$db_spec['prefix'] = $db_prefix;
$connection = $this->getConnection($db_spec);
$this->version = $this->getLegacyDrupalVersion($connection);
$this->createDatabaseStateSettings($db_spec, $this->version);
}
$this->databaseStateKey = 'migrate_drupal_' . $this->version;
$migrations = $this->getMigrations($this->databaseStateKey, $this->version);
$this->migrationList = [];
foreach ($migrations as $migration) {
$this->applyFilePath($migration);
$this->expandNodeMigrations($migration);
$this->migrationList[$migration->id()] = $migration;
}
}
/**
* Adds the source base path configuration to relevant migrations.
*
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* Migration to alter with the provided path.
*/
protected function applyFilePath(MigrationInterface $migration) {
$destination = $migration->getDestinationConfiguration();
if ($destination['plugin'] === 'entity:file') {
// Make sure we have a single trailing slash.
$source_base_path = rtrim(drush_get_option('legacy-root'), '/') . '/';
$source = $migration->getSourceConfiguration();
$source['constants']['source_base_path'] = $source_base_path;
$migration->set('source', $source);
}
}
/**
* For D6 term_node migrations, make sure the nid reference is expanded.
*
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* Migration to alter with the list of node migrations.
*/
protected function expandNodeMigrations(MigrationInterface $migration) {
$source = $migration->getSourceConfiguration();
// Track the node migrations as we see them.
if ($source['plugin'] == 'd6_node') {
$this->nodeMigrations[] = $migration->id();
}
elseif ($source['plugin'] == 'd6_term_node' || $source['plugin'] == 'd6_term_node_revision') {
if ($source['plugin'] == 'd6_term_node') {
$id_property = 'nid';
}
else {
$id_property = 'vid';
}
// If the ID mapping is to the underived d6_node migration, replace
// it with an expanded list of node migrations.
$process = $migration->getProcess();
$new_nid_process = [];
foreach ($process[$id_property] as $delta => $plugin_configuration) {
if (in_array($plugin_configuration['plugin'], $this->migrationLookupPluginIds) &&
is_string($plugin_configuration['migration']) &&
substr($plugin_configuration['migration'], -7) == 'd6_node') {
$plugin_configuration['migration'] = $this->nodeMigrations;
}
$new_nid_process[$delta] = $plugin_configuration;
}
$migration->setProcessOfProperty($id_property, $new_nid_process);
}
}
/**
* Run the configured migrations.
*/
public function import() {
static::$messages = new DrushLogMigrateMessage();
if (drush_get_option('debug')) {
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::IDMAP_MESSAGE,
[get_class(), 'onIdMapMessage']);
}
foreach ($this->migrationList as $migration_id => $migration) {
drush_print(dt('Upgrading @migration', ['@migration' => $migration_id]));
$executable = new MigrateExecutable($migration, static::$messages);
// drush_op() provides --simulate support.
drush_op([$executable, 'import']);
}
}
/**
* Export the configured migration plugins as configuration entities.
*/
public function export() {
$db_info = \Drupal::state()->get($this->databaseStateKey);
// Create a group to hold the database configuration.
$group = [
'id' => $this->databaseStateKey,
'label' => 'Import from Drupal ' . $this->version,
'description' => 'Migrations originally generated from drush migrate-upgrade --configure-only',
'source_type' => 'Drupal ' . $this->version,
'shared_configuration' => [
'source' => [
'key' => 'drupal_' . $this->version,
]
]
];
// Only add the database connection info to the configuration entity
// if it was passed in as a parameter.
if (!empty(drush_get_option('legacy-db-url'))) {
$group['shared_configuration']['source']['database'] = $db_info['database'];
}
// Ditto for the key.
if (!empty(drush_get_option('legacy-db-key'))) {
$group['shared_configuration']['source']['key'] = drush_get_option('legacy-db-key');
}
$group = MigrationGroup::create($group);
$group->save();
foreach ($this->migrationList as $migration_id => $migration) {
drush_print(dt('Exporting @migration as @new_migration',
['@migration' => $migration_id, '@new_migration' => $this->modifyId($migration_id)]));
$entity_array['id'] = $migration_id;
$entity_array['class'] = $migration->get('class');
$entity_array['cck_plugin_method'] = $migration->get('cck_plugin_method');
$entity_array['migration_group'] = $this->databaseStateKey;
$entity_array['migration_tags'] = $migration->get('migration_tags');
$entity_array['label'] = $migration->get('label');
$entity_array['source'] = $migration->getSourceConfiguration();
$entity_array['destination'] = $migration->getDestinationConfiguration();
$entity_array['process'] = $migration->get('process');
$entity_array['migration_dependencies'] = $migration->getMigrationDependencies();
$migration_entity = Migration::create($this->substituteIds($entity_array));
$migration_entity->save();
}
}
/**
* Rewrite any migration plugin IDs so they won't conflict with the core
* IDs.
*
* @param $entity_array
* A configuration array for a migration.
*
* @return array
* The migration configuration array modified with new IDs.
*/
protected function substituteIds($entity_array) {
$entity_array['id'] = $this->modifyId($entity_array['id']);
foreach ($entity_array['migration_dependencies'] as $type => $dependencies) {
foreach ($dependencies as $key => $dependency) {
$entity_array['migration_dependencies'][$type][$key] = $this->modifyId($dependency);
}
}
$this->substituteMigrationIds($entity_array['process']);
return $entity_array;
}
/**
* Recursively substitute IDs for migration plugins.
*
* @param mixed $process
*/
protected function substituteMigrationIds(&$process) {
if (is_array($process)) {
// We found a migration plugin, change the ID.
if (isset($process['plugin']) && in_array($process['plugin'], $this->migrationLookupPluginIds)) {
if (is_array($process['migration'])) {
$new_migration = [];
foreach ($process['migration'] as $migration) {
$new_migration[] = $this->modifyId($migration);
}
$process['migration'] = $new_migration;
}
else {
$process['migration'] = $this->modifyId($process['migration']);
}
}
else {
// Recurse on each array member.
foreach ($process as &$subprocess) {
$this->substituteMigrationIds($subprocess);
}
}
}
}
/**
* @param $id
* The original core plugin ID.
*
* @return string
* The ID modified to serve as a configuration entity ID.
*/
protected function modifyId($id) {
return drush_get_option('migration-prefix', 'upgrade_') . str_replace(':', '_', $id);
}
/**
* Rolls back the configured migrations.
*/
public function rollback() {
static::$messages = new DrushLogMigrateMessage();
$database_state_key = \Drupal::state()->get('migrate.fallback_state_key');
$database_state = \Drupal::state()->get($database_state_key);
$db_spec = $database_state['database'];
$connection = $this->getConnection($db_spec);
$version = $this->getLegacyDrupalVersion($connection);
$migrations = $this->getMigrations('migrate_drupal_' . $version, $version);
// Roll back in reverse order.
$this->migrationList = array_reverse($migrations);
foreach ($migrations as $migration) {
drush_print(dt('Rolling back @migration', ['@migration' => $migration->id()]));
$executable = new MigrateExecutable($migration, static::$messages);
// drush_op() provides --simulate support.
drush_op([$executable, 'rollback']);
}
}
/**
* Display any messages being logged to the ID map.
*
* @param \Drupal\migrate\Event\MigrateIdMapMessageEvent $event
* The message event.
*/
public static function onIdMapMessage(MigrateIdMapMessageEvent $event) {
if ($event->getLevel() == MigrationInterface::MESSAGE_NOTICE ||
$event->getLevel() == MigrationInterface::MESSAGE_INFORMATIONAL) {
$type = 'status';
}
else {
$type = 'error';
}
$source_id_string = implode(',', $event->getSourceIdValues());
$message = t('Source ID @source_id: @message',
['@source_id' => $source_id_string, '@message' => $event->getMessage()]);
static::$messages->display($message, $type);
}
}