drupal
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| drupal [2021/11/02 13:07] – created ssm2017 | drupal [2022/02/07 13:29] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| <sxh> | <sxh> | ||
| drush dl module_filter admin_menu views ctools pathauto sitemap bootstrap jquery_update date devel metatag xmlsitemap libraries transliteration token field_group autocomplete_deluxe entity rules calendar date_ical | drush dl module_filter admin_menu views ctools pathauto sitemap bootstrap jquery_update date devel metatag xmlsitemap libraries transliteration token field_group autocomplete_deluxe entity rules calendar date_ical | ||
| + | </ | ||
| + | |||
| + | === simple drupal 7 field === | ||
| + | == external_image_link.info == | ||
| + | <sxh ini> | ||
| + | name = External image field | ||
| + | description = " | ||
| + | package = Fields | ||
| + | core = 7.x | ||
| + | files[] = external_image_field.module | ||
| + | </ | ||
| + | |||
| + | == external_image_link.install == | ||
| + | <sxh php> | ||
| + | /** | ||
| + | * Implements hook_field_schema(). | ||
| + | */ | ||
| + | function external_image_field_field_schema($field) { | ||
| + | $columns = array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | return array( | ||
| + | ' | ||
| + | ); | ||
| + | }</ | ||
| + | |||
| + | == external_image_link.module == | ||
| + | <sxh php> | ||
| + | /** | ||
| + | * Implements hook_field_info(). | ||
| + | */ | ||
| + | function external_image_field_field_info() { | ||
| + | return array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ), | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Implements hook_field_is_empty(). | ||
| + | */ | ||
| + | function external_image_field_field_is_empty($item, | ||
| + | return empty($item[' | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Implements hook_field_formatter_info(). | ||
| + | */ | ||
| + | function external_image_field_field_formatter_info() { | ||
| + | return array( | ||
| + | ' | ||
| + | ' | ||
| + | 'field types' => array(' | ||
| + | ), | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Implements hook_field_formatter_view(). | ||
| + | */ | ||
| + | function external_image_field_field_formatter_view($entity_type, | ||
| + | $element = array(); | ||
| + | foreach ($items as $delta => $item) { | ||
| + | $variables = array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | $element[$delta] = array( | ||
| + | '# | ||
| + | ); | ||
| + | } | ||
| + | return $element; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Implements hook_field_widget_info(). | ||
| + | */ | ||
| + | function external_image_field_field_widget_info() { | ||
| + | return array( | ||
| + | ' | ||
| + | ' | ||
| + | 'field types' => array(' | ||
| + | ), | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Implements hook_field_widget_form(). | ||
| + | */ | ||
| + | function external_image_field_field_widget_form(& | ||
| + | $element[' | ||
| + | '# | ||
| + | '# | ||
| + | '# | ||
| + | ); | ||
| + | $element[' | ||
| + | '# | ||
| + | '# | ||
| + | '# | ||
| + | ); | ||
| + | $element[' | ||
| + | '# | ||
| + | '# | ||
| + | '# | ||
| + | ); | ||
| + | return $element; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Implements hook_field_widget_error(). | ||
| + | */ | ||
| + | function external_image_field_field_widget_error($element, | ||
| + | switch ($error[' | ||
| + | case ' | ||
| + | form_error($element, | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | === Batch by drush === | ||
| + | == Sources == | ||
| + | * http:// | ||
| + | * http:// | ||
| + | == How ? == | ||
| + | I needed to import some content from a Joomla! website. I have exported the content using phpmyadmin and asking to get the data as a php array from the table ' | ||
| + | * title | ||
| + | * introtext | ||
| + | * fulltext | ||
| + | * state | ||
| + | * created | ||
| + | * created_by | ||
| + | * modified | ||
| + | Then, i have used a drush script to import them. It tooks about 30 seconds for 280 nodes. The exported file was 1.2MB | ||
| + | == Code == | ||
| + | <sxh bash> | ||
| + | ~/ | ||
| + | </ | ||
| + | <sxh php> | ||
| + | <?php | ||
| + | |||
| + | function drush_import_drush_command() { | ||
| + | $items | ||
| + | $items[' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ), | ||
| + | ); | ||
| + | return $items; | ||
| + | } | ||
| + | |||
| + | function drush_import_drush_help($section) { | ||
| + | switch ($section) { | ||
| + | case ' | ||
| + | return dt(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function drush_import_setup_batch($start=1, | ||
| + | // ... | ||
| + | // Populate $lots_of_data from record $start to record $stop. | ||
| + | // ... | ||
| + | | ||
| + | |||
| + | //Break up all of our data so each process does not time out. | ||
| + | $chunks = array_chunk($jos_content, | ||
| + | $operations = array(); | ||
| + | $count_chunks = count($chunks); | ||
| + | |||
| + | //for every chunk, assign some method to run on that chunk of data | ||
| + | foreach ($chunks as $chunk) { | ||
| + | $i++; | ||
| + | $operations[] = array( | ||
| + | " | ||
| + | array( | ||
| + | $chunk , | ||
| + | ' | ||
| + | ) | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | //put all that information into our batch array | ||
| + | $batch = array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | |||
| + | //Get the batch process all ready! | ||
| + | batch_set($batch); | ||
| + | $batch =& batch_get(); | ||
| + | |||
| + | //Because we are doing this on the back-end, we set progressive to false. | ||
| + | $batch[' | ||
| + | |||
| + | //Start processing the batch operations. | ||
| + | drush_backend_batch_process(); | ||
| + | } | ||
| + | |||
| + | function drush_import_some_nodes($chunk, | ||
| + | print(" | ||
| + | foreach ($chunk as $content) { | ||
| + | print(" | ||
| + | drush_import_create_node($content); | ||
| + | } | ||
| + | $context[' | ||
| + | } | ||
| + | |||
| + | function drush_import_finished_method($success, | ||
| + | //Let the user know we have finished! | ||
| + | print t(" | ||
| + | } | ||
| + | |||
| + | function drush_import_create_node($content) { | ||
| + | // title | ||
| + | // introtext | ||
| + | // fulltext | ||
| + | // state | ||
| + | // created | ||
| + | // created_by | ||
| + | // modified | ||
| + | $node = new stdClass(); | ||
| + | $node-& | ||
| + | node_object_prepare($node); | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | $node-& | ||
| + | node_save($node); | ||
| + | } | ||
| + | |||
| </ | </ | ||
drupal.1635854838.txt.gz · Last modified: (external edit)
