Drush: commands/core/migrate.d8.drush.inc Source File

  1. 7.x doxygen/html/migrate_8d8_8drush_8inc_source.html
  2. master doxygen/html/migrate_8d8_8drush_8inc_source.html
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * Migrate content into Drupal 8+.
6  */
7 
8 use Drupal\Core\Database\Database;
9 use Drupal\migrate\MigrateExecutable;
10 use Symfony\Component\Yaml\Yaml;
12 
13 /**
14  * Implements hook_drush_command().
15  */
17  $items['migrate-manifest'] = array(
18  'description' => 'Execute the migrations as specified in a manifest file.',
19  'arguments' => array(
20  'manifest' => 'The path to the manifest file',
21  ),
22  'required-arguments' => 1,
23  'options' => array(
24  'legacy-db-url' => array(
25  'description' => 'A Drupal 6 style database URL.',
26  'example-value' => 'mysql://root:pass@127.0.0.1/db',
27  'required' => TRUE,
28  ),
29  ),
30  'drupal dependencies' => array('migrate_drupal'),
31  );
32  return $items;
33 }
34 
35 /**
36  * Import from a manifest file.
37  * @param string $manifest
38  * The path to the manifest file.
39  */
40 function drush_migrate_manifest($manifest) {
41  if (file_exists($manifest)) {
42  $db_url = drush_get_option('legacy-db-url');
43  $db_spec = drush_convert_db_from_db_url($db_url);
44  Database::addConnectionInfo('migrate', 'default', $db_spec);
45  $list = Yaml::parse($manifest);
46  if (is_array($list)) {
47  $message = new DrushLogMigrateMessage();
48  foreach (entity_load_multiple('migration', $list) as $migration_id => $migration) {
49  drush_log("Running $migration_id", 'ok');
50  $executable = new MigrateExecutable($migration, $message);
51  $executable->import();
52 
53  // Remove the migration from the list, so that we can track whether any
54  // migrations were not found.
55  $list = array_diff($list, array($migration_id));
56  }
57  // Warn the user if any migrations were not found.
58  if ($list) {
59  drush_log(dt('The following migrations were not found: !migrations', array(
60  '!migrations' => implode(', ', $list),
61  )), 'warning');
62  }
63  drush_invoke_process('@self', 'cache-rebuild', array(), array(), FALSE);
64  }
65  else {
66  return drush_set_error('The manifest file cannot be parsed.');
67  }
68  }
69  else {
70  return drush_set_error('The manifest file does not exist.');
71  }
72 }

File

doxygen/html/migrate_8d8_8drush_8inc_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: commands/core/migrate.d8.drush.inc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_afac61274991793aa7e9133a8f4f291e.html">commands</a></li><li class="navelem"><a class="el" href="dir_5762b63965e3a68a35f77c23b4dd4668.html">core</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">migrate.d8.drush.inc</div>  </div>
</div><!--header-->
<div class="contents">
<a href="migrate_8d8_8drush_8inc.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * @file</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * Migrate content into Drupal 8+.</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;use Drupal\Core\Database\Database;</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;use Drupal\migrate\MigrateExecutable;</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;use Symfony\Component\Yaml\Yaml;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;use <a class="code" href="classDrush_1_1Migrate_1_1DrushLogMigrateMessage.html">Drush\Migrate\DrushLogMigrateMessage</a>;</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * Implements hook_drush_command().</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00016"></a><span class="lineno"><a class="code" href="migrate_8d8_8drush_8inc.html#ae319112fd495880b6eeca187b1066fbf">   16</a></span>&#160;<span class="keyword">function</span> <a class="code" href="migrate_8d8_8drush_8inc.html#ae319112fd495880b6eeca187b1066fbf">migrate_drush_command</a>() {</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;  $items[<span class="stringliteral">&#39;migrate-manifest&#39;</span>] = array(</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Execute the migrations as specified in a manifest file.&#39;</span>,</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;    <span class="stringliteral">&#39;arguments&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;      <span class="stringliteral">&#39;manifest&#39;</span> =&gt; <span class="stringliteral">&#39;The path to the manifest file&#39;</span>,</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;    ),</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    <span class="stringliteral">&#39;required-arguments&#39;</span> =&gt; 1,</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;    <span class="stringliteral">&#39;options&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;      <span class="stringliteral">&#39;legacy-db-url&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;        <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;A Drupal 6 style database URL.&#39;</span>,</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;mysql://root:pass@127.0.0.1/db&#39;</span>,</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        <span class="stringliteral">&#39;required&#39;</span> =&gt; TRUE,</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;      ),</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    ),</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="stringliteral">&#39;drupal dependencies&#39;</span> =&gt; array(<span class="stringliteral">&#39;migrate_drupal&#39;</span>),</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;  );</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;  <span class="keywordflow">return</span> $items;</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;}</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="comment"> * Import from a manifest file.</span></div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="comment"> * @param string $manifest</span></div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="comment"> *   The path to the manifest file.</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="code" href="migrate_8d8_8drush_8inc.html#a3197cf2ac638ec4b04a4e05ba0917cb6">   40</a></span>&#160;<span class="keyword">function</span> <a class="code" href="migrate_8d8_8drush_8inc.html#a3197cf2ac638ec4b04a4e05ba0917cb6">drush_migrate_manifest</a>($manifest) {</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;  <span class="keywordflow">if</span> (file_exists($manifest)) {</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    $db_url = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;legacy-db-url&#39;</span>);</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    $db_spec = <a class="code" href="sitealias_8inc.html#a3e5b4e0099b3cf7ad4ec47fac20e4e54">drush_convert_db_from_db_url</a>($db_url);</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    Database::addConnectionInfo(<span class="stringliteral">&#39;migrate&#39;</span>, <span class="stringliteral">&#39;default&#39;</span>, $db_spec);</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    $list = Yaml::parse($manifest);</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    <span class="keywordflow">if</span> (is_array($list)) {</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;      $message = <span class="keyword">new</span> <a class="code" href="classDrush_1_1Migrate_1_1DrushLogMigrateMessage.html">DrushLogMigrateMessage</a>();</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;      <span class="keywordflow">foreach</span> (entity_load_multiple(<span class="stringliteral">&#39;migration&#39;</span>, $list) as $migration_id =&gt; $migration) {</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<span class="stringliteral">&quot;Running $migration_id&quot;</span>, <span class="stringliteral">&#39;ok&#39;</span>);</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        $executable = <span class="keyword">new</span> MigrateExecutable($migration, $message);</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        $executable-&gt;import();</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        <span class="comment">// Remove the migration from the list, so that we can track whether any</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;        <span class="comment">// migrations were not found.</span></div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        $list = array_diff($list, array($migration_id));</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;      }</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;      <span class="comment">// Warn the user if any migrations were not found.</span></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;      <span class="keywordflow">if</span> ($list) {</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;The following migrations were not found: !migrations&#39;</span>, array(</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;          <span class="stringliteral">&#39;!migrations&#39;</span> =&gt; implode(<span class="stringliteral">&#39;, &#39;</span>, $list),</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        )), <span class="stringliteral">&#39;warning&#39;</span>);</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;      }</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;      <a class="code" href="group__dispatching.html#ga125471885af052278a0874446b332cf9">drush_invoke_process</a>(<span class="stringliteral">&#39;@self&#39;</span>, <span class="stringliteral">&#39;cache-rebuild&#39;</span>, array(), array(), FALSE);</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    }</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;The manifest file cannot be parsed.&#39;</span>);</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    }</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  }</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;The manifest file does not exist.&#39;</span>);</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;  }</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Oct 8 2014 09:04:53 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>