bulk_export.module

  1. cis7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
  2. cle7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
  3. ecd7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
  4. elmsmedia7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
  5. harmony7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
  6. icor7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
  8. mooc7 sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module

Perform bulk exports.

Functions

Namesort descending Description
bulk_export_export FAPI gateway to the bulk exporter.
bulk_export_export_form FAPI definition for the bulk exporter form.
bulk_export_export_form_submit Process the bulk export submit form and make the results available.
bulk_export_menu Implements hook_menu().
bulk_export_permission Implements hook_permission().

File

sites/all/modules/ulmus/ctools/bulk_export/bulk_export.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Perform bulk exports.
  5. */
  6. /**
  7. * Implements hook_permission().
  8. */
  9. function bulk_export_permission() {
  10. return array(
  11. 'use bulk exporter' => array(
  12. 'title' => t('Access Bulk Exporter'),
  13. 'description' => t('Export various system objects into code.'),
  14. ),
  15. );
  16. }
  17. /**
  18. * Implements hook_menu().
  19. */
  20. function bulk_export_menu() {
  21. $items['admin/structure/bulk-export'] = array(
  22. 'title' => 'Bulk Exporter',
  23. 'description' => 'Bulk-export multiple CTools-handled data objects to code.',
  24. 'access arguments' => array('use bulk exporter'),
  25. 'page callback' => 'bulk_export_export',
  26. );
  27. $items['admin/structure/bulk-export/results'] = array(
  28. 'access arguments' => array('use bulk exporter'),
  29. 'page callback' => 'bulk_export_export',
  30. 'type' => MENU_CALLBACK,
  31. );
  32. return $items;
  33. }
  34. /**
  35. * FAPI gateway to the bulk exporter.
  36. *
  37. * @param $cli
  38. * Whether this function is called from command line.
  39. * @param $options
  40. * A collection of options, only passed in by drush_ctools_export().
  41. */
  42. function bulk_export_export($cli = FALSE, $options = array()) {
  43. ctools_include('export');
  44. $form = array();
  45. $schemas = ctools_export_get_schemas(TRUE);
  46. $exportables = $export_tables = array();
  47. foreach ($schemas as $table => $schema) {
  48. if (!empty($schema['export']['list callback']) && function_exists($schema['export']['list callback'])) {
  49. $exportables[$table] = $schema['export']['list callback']();
  50. }
  51. else {
  52. $exportables[$table] = ctools_export_default_list($table, $schema);
  53. }
  54. natcasesort($exportables[$table]);
  55. $export_tables[$table] = $schema['module'];
  56. }
  57. if ($exportables) {
  58. $form_state = array(
  59. 're_render' => FALSE,
  60. 'no_redirect' => TRUE,
  61. 'exportables' => $exportables,
  62. 'export_tables' => $export_tables,
  63. 'name' => '',
  64. 'code' => '',
  65. 'module' => '',
  66. );
  67. // If called from drush_ctools_export, get the module name and
  68. // select all exportables and call the submit function directly.
  69. if ($cli) {
  70. $module_name = $options['name'];
  71. $form_state['values']['name'] = $module_name;
  72. if (isset($options['selections'])) {
  73. $exportables = $options['selections'];
  74. }
  75. $form_state['values']['tables'] = array();
  76. foreach ($exportables as $table => $names) {
  77. if (!empty($names)) {
  78. $form_state['values']['tables'][] = $table;
  79. $form_state['values'][$table] = array();
  80. foreach ($names as $name => $title) {
  81. $form_state['values'][$table][$name] = $name;
  82. }
  83. }
  84. }
  85. $output = bulk_export_export_form_submit($form, $form_state);
  86. }
  87. else {
  88. $output = drupal_build_form('bulk_export_export_form', $form_state);
  89. $module_name = $form_state['module'];
  90. }
  91. if (!empty($form_state['submitted']) || $cli) {
  92. drupal_set_title(t('Bulk export results'));
  93. $output = '';
  94. $module_code = '';
  95. $api_code = array();
  96. $dependencies = $file_data = array();
  97. foreach ($form_state['code'] as $module => $api_info) {
  98. if ($module == 'general') {
  99. $module_code .= $api_info;
  100. }
  101. else {
  102. foreach ($api_info as $api => $info) {
  103. $api_hook = ctools_plugin_api_get_hook($module, $api);
  104. if (empty($api_code[$api_hook])) {
  105. $api_code[$api_hook] = '';
  106. }
  107. $api_code[$api_hook] .= " if (\$module == '$module' && \$api == '$api') {\n";
  108. $api_code[$api_hook] .= " return array('version' => $info[version]);\n";
  109. $api_code[$api_hook] .= " }\n";
  110. $dependencies[$module] = TRUE;
  111. $file = $module_name . '.' . $api . '.inc';
  112. $code = "<?php\n\n";
  113. $code .= "/**\n";
  114. $code .= " * @file\n";
  115. $code .= " * Bulk export of $api objects generated by Bulk export module.\n";
  116. $code .= " */\n\n";
  117. $code .= $info['code'];
  118. if ($cli) {
  119. $file_data[$file] = $code;
  120. }
  121. else {
  122. $export_form = drupal_get_form('ctools_export_form', $code, t('Place this in @file', array('@file' => $file)));
  123. $output .= drupal_render($export_form);
  124. }
  125. }
  126. }
  127. }
  128. // Add hook_ctools_plugin_api at the top of the module code, if there is any.
  129. if ($api_code) {
  130. foreach ($api_code as $api_hook => $text) {
  131. $api = "\n/**\n";
  132. $api .= " * Implements hook_$api_hook().\n";
  133. $api .= " */\n";
  134. $api .= "function {$module_name}_$api_hook(\$module, \$api) {\n";
  135. $api .= $text;
  136. $api .= "}\n";
  137. $module_code = $api . $module_code;
  138. }
  139. }
  140. if ($module_code) {
  141. $module = "<?php\n\n";
  142. $module .= "/**\n";
  143. $module .= " * @file\n";
  144. $module .= " * Bulk export of objects generated by Bulk export module.\n";
  145. $module .= " */\n";
  146. $module .= $module_code;
  147. if ($cli) {
  148. $file_data[$module_name . '.module'] = $module;
  149. }
  150. else {
  151. $export_form = drupal_get_form('ctools_export_form', $module, t('Place this in @file', array('@file' => $form_state['module'] . '.module')));
  152. $output = drupal_render($export_form) . $output;
  153. }
  154. }
  155. $info = strtr("name = @module export module\n", array('@module' => $form_state['module']));
  156. $info .= strtr("description = Export objects from CTools\n", array('@module' => $form_state['values']['name']));
  157. foreach ($dependencies as $module => $junk) {
  158. $info .= "dependencies[] = $module\n";
  159. }
  160. $info .= "package = Chaos tool suite\n";
  161. $info .= "core = 7.x\n";
  162. if ($cli) {
  163. $file_data[$module_name . '.info'] = $info;
  164. }
  165. else {
  166. $export_form = drupal_get_form('ctools_export_form', $info, t('Place this in @file', array('@file' => $form_state['module'] . '.info')));
  167. $output = drupal_render($export_form) . $output;
  168. }
  169. }
  170. if ($cli) {
  171. return $file_data;
  172. }
  173. else {
  174. return $output;
  175. }
  176. }
  177. else {
  178. return t('There are no objects to be exported at this time.');
  179. }
  180. }
  181. /**
  182. * FAPI definition for the bulk exporter form.
  183. *
  184. */
  185. function bulk_export_export_form($form, &$form_state) {
  186. $files = system_rebuild_module_data();
  187. $form['additional_settings'] = array(
  188. '#type' => 'vertical_tabs',
  189. );
  190. $options = $tables = array();
  191. foreach ($form_state['exportables'] as $table => $list) {
  192. if (empty($list)) {
  193. continue;
  194. }
  195. foreach ($list as $id => $title) {
  196. $options[$table][$id] = array($title);
  197. $options[$table][$id]['#attributes'] = array('class' => array('bulk-selection'));
  198. }
  199. $module = $form_state['export_tables'][$table];
  200. $header = array($table);
  201. $module_name = $files[$module]->info['name'];
  202. $tables[] = $table;
  203. if (!isset($form[$module_name])) {
  204. $form[$files[$module]->info['name']] = array(
  205. '#type' => 'fieldset',
  206. '#group' => 'additional_settings',
  207. '#title' => $module_name,
  208. );
  209. }
  210. $form[$module_name]['tables'][$table] = array(
  211. '#prefix' => '<div class="export-container">',
  212. '#suffix' => '</div>',
  213. '#type' => 'tableselect',
  214. '#header' => $header,
  215. '#options' => $options[$table],
  216. );
  217. }
  218. $form['tables'] = array(
  219. '#type' => 'value',
  220. '#value' => $tables,
  221. );
  222. $form['name'] = array(
  223. '#type' => 'textfield',
  224. '#title' => t('Module name'),
  225. '#description' => t('Enter the module name to export code to.'),
  226. );
  227. $form['submit'] = array(
  228. '#type' => 'submit',
  229. '#value' => t('Export'),
  230. );
  231. $form['#action'] = url('admin/structure/bulk-export/results');
  232. $form['#attached']['css'][] = drupal_get_path('module', 'bulk_export') . '/bulk_export.css';
  233. $form['#attached']['js'][] = drupal_get_path('module', 'bulk_export') . '/bulk_export.js';
  234. return $form;
  235. }
  236. /**
  237. * Process the bulk export submit form and make the results available.
  238. */
  239. function bulk_export_export_form_submit($form, &$form_state) {
  240. $code = array();
  241. $name = empty($form_state['values']['name']) ? 'foo' : $form_state['values']['name'];
  242. $tables = $form_state['values']['tables'];
  243. foreach ($tables as $table) {
  244. $names = array_keys(array_filter($form_state['values'][$table]));
  245. if ($names) {
  246. natcasesort($names);
  247. ctools_export_to_hook_code($code, $table, $names, $name);
  248. }
  249. }
  250. $form_state['code'] = $code;
  251. $form_state['module'] = $name;
  252. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.