EclipseGc

Untitled

Feb 15th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.77 KB | None | 0 0
  1. <?php
  2.  
  3. abstract class NodesMigration extends Migration {
  4.   public function __construct(array $arguments) {
  5.     parent::__construct();
  6.     $type = isset($arguments['type']) ? $arguments['type'] : NULL;
  7.     $new_type = isset($arguments['new type']) ? $arguments['new type'] : $type;
  8.     $this->description = t('Migrate nodes');
  9.     $this->map = new MigrateSQLMap($this->machineName,
  10.       array(
  11.         'nid' => array(
  12.           'type' => 'int',
  13.           'unsigned' => TRUE,
  14.           'not null' => TRUE,
  15.           'description' => 'D5 Unique User ID',
  16.           'alias' => 'n',
  17.         )
  18.       ),
  19.       MigrateDestinationNode::getKeySchema()
  20.     );
  21.  
  22.     $query = $this->node_query($type);
  23.     $this->set_highwater_field();
  24.     $this->set_source($query);
  25.     $this->destination = new MigrateDestinationNode($new_type);
  26.     $this->node_field_mapping();
  27.   }
  28.  
  29.   public function set_highwater_field() {
  30.     $this->highwaterField = array(
  31.       'name' => 'changed',
  32.       'alias' => 'n',
  33.     );
  34.   }
  35.  
  36.   public function node_query($type) {
  37.     $query = Database::getConnection('d5')
  38.       ->select('node', 'n')
  39.       ->fields('n', array('nid', 'vid', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'moderate', 'sticky'))
  40.       ->condition('n.type', $type);
  41.     $query->join('node_revisions', 'nr', 'nr.vid = n.vid');
  42.     $query->fields('nr', array('body', 'teaser', 'format'));
  43.     return $query;
  44.   }
  45.  
  46.   public function set_source($query) {
  47.     $this->source = new MigrateSourceSQL($query);
  48.     $this->source->setMapJoinable(FALSE);
  49.   }
  50.  
  51.   public function node_field_mapping() {
  52.     $body_arguments = MigrateTextFieldHandler::arguments(array('source_field' => 'teaser'), array('source_field' => 'format'), NULL);
  53.     // Make the mappings
  54.     $this->addFieldMapping('nid', 'nid');
  55.     $this->addFieldMapping('vid', 'vid');
  56.     $this->addFieldMapping('title', 'title');
  57.     $this->addFieldMapping('uid', 'uid');
  58.     $this->addFieldMapping('status', 'status');
  59.     $this->addFieldMapping('created', 'created');
  60.     $this->addFieldMapping('changed', 'changed');
  61.     $this->addFieldMapping('comment', 'comment');
  62.     $this->addFieldMapping('promote', 'promote');
  63.     $this->addFieldMapping('moderate', 'moderate');
  64.     $this->addFieldMapping('sticky', 'sticky');
  65.     $this->addFieldMapping('body', 'body')->arguments($body_arguments);
  66.     $this->addFieldMapping('language')->defaultValue('und');
  67.     $this->addFieldMapping('is_new')->defaultValue(TRUE);
  68.   }
  69.  
  70.   public function prepareRow($current_row) {
  71.     $formats = array(
  72.       '1' => 'filtered_html',
  73.       '2' => 'php_code',
  74.       '3' => 'full_html',
  75.     );
  76.     $current_row->format = isset($formats[$current_row->format]) ? $formats[$current_row->format] : 'plain_text';
  77.   }
  78. }
  79.  
  80. class NodeLinkMigration extends NodesMigration {
  81.   public function __construct() {
  82.     parent::__construct(array('type' => 'link'));
  83.   }
  84.  
  85.   public function node_query() {
  86.     $query = Database::getConnection('d5')
  87.       ->select('links_links', 'll')
  88.       ->fields('ll', array('name', 'description', 'active', 'url'));
  89.     $query->join('links_categories', 'lc', 'll.category = lc.id');
  90.     $query->fields('lc', array('name'));
  91.     return $query;
  92.   }
  93.  
  94.   public function set_highwater_field() {}
  95.  
  96.   public function node_field_mapping() {
  97.     $body_arguments = MigrateTextFieldHandler::arguments(array('source_field' => 'description'));
  98.     // Make the mappings
  99.     $this->addFieldMapping('title', 'name');
  100.     $this->addFieldMapping('uid')->defaultValue(2);
  101.     $this->addFieldMapping('status', 'active');
  102.     $this->addFieldMapping('body', 'description')->arguments($body_arguments);
  103.     $this->addFieldMapping('language')->defaultValue('und');
  104.     $this->addFieldMapping('is_new')->defaultValue(TRUE);
  105.   }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment