Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Began generalizing cck field query and prepare methods

  • Loading branch information...
commit 9254f3527a7c7dac0b6153206df4dda7d1fa95f7 1 parent 176f2e4
@sagotsky sagotsky authored
View
44 profiles/openscholar/modules/os/modules/os_migrate/os_migrate.inc
@@ -112,6 +112,50 @@ abstract class OSMigration extends Migration {
return $output;
}
+ //adds joins and fields based on migrate object's cck_fields property
+ function addQueryCCK(&$query, $content_type, $table=NULL) {
+ $table = ($table) ? $table : 'content_type_' . $content_type;
+ //class has Link Date Text
+ $fields = array();
+ foreach($this->cck_fields as $name => $field) {
+ switch ($field) {
+ case 'Link':
+ $fields += array('field_'.$name.'_url', 'field_'.$name.'_title', 'field_'.$name.'_attributes');
+ break;
+
+ case 'Date':
+ case 'Text':
+ $fields[] = 'field_'.$name.'_value';
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (count($fields)) {
+ $query->leftjoin($table, 'ct', 'n.vid = ct.vid');
+ $query->fields('ct', $fields);
+ }
+ }
+
+ //perform common preparations for cck types
+ function prepareRowCCK(&$row) {
+ foreach($this->cck_fields as $name => $field) {
+ switch ($field) {
+ case 'Link':
+ $attr = 'field_'.$name.'_attributes';
+ if (strlen($row->$attr)) {
+ $row->$attr = unserialize($row->$attr);
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
//get all inline embeds. return array of them.
function os_migrate_inline_oembed($vid) {
$query = self::d6_db_select('content_field_os_inline_oembed', 'oe')
View
4 profiles/openscholar/modules/os/modules/os_migrate/os_migrate_node_announcement.inc
@@ -14,8 +14,8 @@ class AnnouncementNodeOSMigration extends AbstractNodeOSMigration {
}
//also include content type's data
- public function query($bundle) {
- $query = parent::query($bundle);
+ public function query($content_type) {
+ $query = parent::query($content_type);
$query->leftJoin('content_type_announcement', 'cta', 'n.vid = cta.vid');
$query->fields('cta', array('field_announcement_photo_fid', 'field_announcement_photo_list', 'field_announcement_photo_data'));
View
25 profiles/openscholar/modules/os/modules/os_migrate/os_migrate_node_class.inc
@@ -2,11 +2,19 @@
class ClassNodeOSMigration extends AbstractNodeOSMigration {
public function __construct() {
+ //name of cck_field -> its cck field type
+ $this->cck_fields = array(
+ 'class_link' => 'Link',
+ 'class_semester' => 'Text',
+ 'class_year' => 'Date',
+ );
// Let AbstractNode handle the source, dest, and map.
parent::__construct('class', 'class'); //current types are vsite, article, and page. lets start with one of those instead?
$this->description = t('OS Class Nodes');
+
+
$fields = array(
'url' => array('source_field' => 'field_class_link_url'),
@@ -31,10 +39,12 @@ class ClassNodeOSMigration extends AbstractNodeOSMigration {
}
//also include content type's data
- public function query($bundle) {
- $query = parent::query($bundle);
- $query->join('content_type_class', 'ct', 'n.vid = ct.vid');
- $query->fields('ct', array('field_class_link_url', 'field_class_link_title', 'field_class_link_attributes', 'field_class_semester_value', 'field_class_year_value'));
+ public function query($content_type) {
+ $query = parent::query($content_type);
+
+ parent::addQueryCCK($query, $content_type);
+// $query->join('content_type_class', 'ct', 'n.vid = ct.vid');
+// $query->fields('ct', array('field_class_link_url', 'field_class_link_title', 'field_class_link_attributes', 'field_class_semester_value', 'field_class_year_value'));
return $query;
}
@@ -49,15 +59,16 @@ class ClassNodeOSMigration extends AbstractNodeOSMigration {
public function prepareRow($current_row) {
parent::prepareRow($current_row); //why no pass by ref?
+ parent::prepareRowCCK($current_row); //handle listed cck fields.
//field_link
if (strlen($current_row->field_class_link_url)) {
- if (strlen($current_row->field_class_link_attributes)) {
+ /* if (strlen($current_row->field_class_link_attributes)) {
$current_row->field_class_link_attributes = unserialize($current_row->field_class_link_attributes);
- }
+ }*/
//$current_row->field_class_link_attributes = ($current_row->field_class_clink_attributes) ?
//unserialize($current_row->field_class_link_attributes) : array();
- $current_row->field_link[] = $current_row->field_class_link_url;
+ $current_row->field_link[] = $current_row->field_class_link_url; //add link
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.