コード例 #1
0
 public function preparePhotos($title, $photos)
 {
     $return = array();
     foreach ($photos as $photo) {
         $url = $photo['url'];
         $return[] = $url;
         $str = sprintf("photo:%s \n", $url);
         drush_print_r($str);
     }
     return $return;
 }
コード例 #2
0
 public function prepareRow(Row $row)
 {
     // do my row mods here..
     // Bail if this is a non-published recipe
     //$status = $row->getSourceProperty("status");
     //if ($status != 'Published') {
     //  return FALSE;
     //}
     //$filename = $row->getSourceProperty("filename") ;
     //$str = sprintf("Processing: %s", $filename);
     //drush_print_r($str);
     $url = $row->getSourceProperty("url");
     $str = sprintf("Processing: %s", $url);
     drush_print_r($str);
     $filename_with_path = basename($url);
     $filename_with_path = 'public://product-images/' . $filename_with_path;
     drush_print_r($filename_with_path);
     $row->setSourceProperty('filename_with_path', $filename_with_path);
     return parent::prepareRow($row);
 }
コード例 #3
0
ファイル: scratch.php プロジェクト: beauboehner/beau
<?php

/*
 * @file
 * Use this file as a php scratchpad for your Drupal site. You might want to
 * load a node, change it, and call node_save($node), for example. If you have
 * used the Execute PHP feature of devel.module, this is the drush equivalent.
 *
 * You may edit this file with whatever php you choose. Then execute the file
 * using `drush script scratch.php`. That command will bootstrap your drupal
 * site and then run the php below.
 *
 * The script command enables you to store your script files wherever you wish and
 * will help you list all of them should you collection grow. See its help.
 *
 */
// Just some ideas to get the juices flowing.
drush_print_r(user_roles());
drush_print_r($GLOBALS['user']);
コード例 #4
0
 public function prepareRow(Row $row)
 {
     // Perform source row modification here.
     // Bail if this is a non-published store
     $status = $row->getSourceProperty("status");
     if ($status != 'OPEN') {
         return FALSE;
     }
     $geo = $row->getSourceProperty("geo_location");
     $x = $geo['coordinates'][0];
     $y = $geo['coordinates'][1];
     $row->setSourceProperty("geox", $x);
     $row->setSourceProperty("geoy", $y);
     $hours = $row->getSourceProperty("hours");
     $row->setSourceProperty("hours", ltrim($hours));
     $country = $row->getSourceProperty("country");
     $country = $this->getIsoCountryCode($country);
     $row->setSourceProperty("country", $country);
     $state = $row->getSourceProperty("state");
     if ($country == "US") {
         $state = $this->getUsaStateCode($state);
         $row->setSourceProperty("state", $state);
     }
     $facebook = $row->getSourceProperty("facebook");
     if (!empty($facebook)) {
         $facebook = "https://www.facebook.com/" . ltrim(trim($facebook));
     }
     $row->setSourceProperty("facebook", $facebook);
     $has_alcohol = $row->getSourceProperty("has_alcohol");
     if (empty($has_alcohol)) {
         $has_alcohol = 0;
         $row->setSourceProperty("has_alcohol", $has_alcohol);
     }
     //TODO: "states" not in USA - ie UK & Canada
     //TODO: lookup region eg. NE in taxonomy and store region actual taxonomy in field_store_region
     $tlc = $row->getSourceProperty("tlc");
     $name = $row->getSourceProperty("name");
     $country = $row->getSourceProperty("country");
     $state = $row->getSourceProperty("state");
     $has_alcohol = $row->getSourceProperty("has_alcohol");
     $str = sprintf("%s: %s %s %s alc:%s", $tlc, $name, $state, $country, $has_alcohol);
     drush_print_r($str);
     return parent::prepareRow($row);
 }
コード例 #5
0
 /**
  * Output debug data.
  */
 function debug($data, $message = '')
 {
     drush_print_r("== {$message}:");
     drush_print_r($data);
 }
コード例 #6
0
ファイル: scratch_5.php プロジェクト: hoangbktech/bhl-bits
<?php

/*
 * @file
 * Use this file as a php scratchpad for your Drupal site. You might want to
 * load a node, change it, and call node_save($node), for example. If you have
 * used the Execute PHP feature of devel.module, this is the drush equivalent.
 *
 * You may edit this file with whatever php you choose. Then execute the file
 * using `drush script scratch.php`. That command will bootstrap your drupal
 * site and then run the php below.
 *
 * The script command enables to store your script files wherever you wish and
 * will help you list all of them should you collection grow. See its help.
 *
 */
// Just some ideas to get the juices flowing.
drush_print_r(user_roles());
drush_print_r($GLOBALS['user']);
$items['harvester/schedule/5/start'] = array('title' => 'Harvest', 'access callback' => TRUE, 'page callback' => 'oaiharvester_schedule_start', 'page arguments' => array(2, TRUE), 'load arguments' => array(2, TRUE), 'type' => MENU_LOCAL_TASK, 'weight' => 10);
drush_print_r($title);
コード例 #7
0
 public function preparePhotos($title, $photos)
 {
     //$return = array();
     //foreach ($photos as $photo) {
     //  $filename = basename($photo['url']);
     //  $fid = $this->lookupImageFid($filename);
     //  $return[] = $fid;
     //  $str = sprintf("fid: %s photo:%s", $fid, $filename);
     //  drush_print_r($str);
     //}
     //return $return;
     // Return only the first image
     $return = array();
     $photo = array();
     $photo = array_shift($photos);
     $filename = basename($photo['url']);
     //Modify the image filename to prepend recipe_hero_images for funky photo migrate.
     //$filename = "recipe_hero_images" . $filename;
     $fid = $this->lookupImageFid($filename);
     $return[] = $fid;
     //if ($fid == NULL) {
     //  $id = "not found";
     //}
     //else {
     //  $id = $fid;
     //}
     $str = sprintf("image: %s fid: %s", $filename, $fid);
     drush_print_r($str);
     return $return;
 }
コード例 #8
0
ファイル: Provider.php プロジェクト: fluxsauce/switchboard
 /**
  * Magic __get.
  *
  * @param string $name
  *   The name of the property to get.
  *
  * @return mixed
  *   Value of set property.
  * @throws \Exception
  */
 public function __get($name)
 {
     if (!property_exists($this, $name)) {
         drush_print_r(debug_backtrace());
         throw new \Exception(__CLASS__ . ' property ' . $name . ' does not exist, cannot get.');
     }
     return $this->{$name};
 }
コード例 #9
0
ファイル: Module.php プロジェクト: josoroma/lastime
 /**
  * Define the component data this component needs to function.
  */
 protected function componentDataDefinition()
 {
     $component_data_definition = array('module_root_name' => array('label' => 'Module machine name', 'default' => 'my_module', 'required' => TRUE), 'module_readable_name' => array('label' => 'Module readable name', 'default' => function ($component_data) {
         return ucwords(str_replace('_', ' ', $component_data['module_root_name']));
     }, 'required' => FALSE), 'module_short_description' => array('label' => 'Module .info file description', 'default' => 'TODO: Description of module', 'required' => FALSE), 'module_package' => array('label' => 'Module .info file package', 'default' => NULL, 'required' => FALSE), 'module_dependencies' => array('label' => 'Module dependencies (space separated list)', 'default' => NULL, 'required' => FALSE), 'module_help_text' => array('label' => 'Module help text (adds hook_help())', 'default' => NULL, 'required' => FALSE), 'module_hook_presets' => array('label' => 'Hook preset groups', 'required' => FALSE, 'format' => 'array', 'options' => function (&$property_info) {
         /// ARGH how to make format that is good for both UI and drush?
         $mb_factory = module_builder_get_factory('ModuleBuilderEnvironmentDrush');
         $mb_task_handler_report_presets = $mb_factory->getTask('ReportHookPresets');
         $hook_presets = $mb_task_handler_report_presets->getHookPresets();
         // Stash the hook presets in the property info so the processing
         // callback doesn't have to repeat the work.
         $property_info['_presets'] = $hook_presets;
         $options = array();
         foreach ($hook_presets as $name => $info) {
             $options[$name] = $info['label'];
         }
         return $options;
     }, 'processing' => function ($value, &$component_data, &$property_info) {
         // Get the presets from where the 'options' callback left them.
         $hook_presets = $property_info['_presets'];
         foreach ($value as $given_preset_name) {
             if (!isset($hook_presets[$given_preset_name])) {
                 throw new \ModuleBuilderException("Undefined hook preset group {$given_preset_name}.");
             }
             // DX: check the preset is properly defined.
             if (!is_array($hook_presets[$given_preset_name]['hooks'])) {
                 throw new \ModuleBuilderException("Incorrectly defined hook preset group {$given_preset_name}.");
             }
             // Add the preset hooks list to the hooks array in the component
             // data.
             $hooks = $hook_presets[$given_preset_name]['hooks'];
             $component_data['hooks'] = array_merge($component_data['hooks'], $hooks);
             drush_print_r($component_data['hooks']);
         }
     }), 'hooks' => array('label' => 'Hook implementations', 'required' => FALSE, 'format' => 'array', 'options' => function (&$property_info) {
         $mb_factory = module_builder_get_factory('ModuleBuilderEnvironmentDrush');
         $mb_task_handler_report_hooks = $mb_factory->getTask('ReportHookData');
         $hook_options = $mb_task_handler_report_hooks->listHookNamesOptions();
         return $hook_options;
     }, 'processing' => function ($value, &$component_data, &$property_info) {
         $mb_factory = module_builder_get_factory('ModuleBuilderEnvironmentDrush');
         $mb_task_handler_report_hooks = $mb_factory->getTask('ReportHookData');
         // Get the flat list of hooks, standardized to lower case.
         $hook_definitions = array_change_key_case($mb_task_handler_report_hooks->getHookDeclarations());
         $hooks = array();
         foreach ($component_data['hooks'] as $hook_name) {
             // Standardize to lowercase.
             $hook_name = strtolower($hook_name);
             // By default, accept the short definition of hooks, ie 'boot' for 'hook_boot'.
             if (isset($hook_definitions["hook_{$hook_name}"])) {
                 $hooks["hook_{$hook_name}"] = TRUE;
             } elseif (isset($hook_definitions[$hook_name])) {
                 $hooks[$hook_name] = TRUE;
             }
         }
         $component_data['hooks'] = $hooks;
     }), 'plugins' => array('label' => 'Plugins', 'required' => FALSE, 'format' => 'array', 'options' => function (&$property_info) {
         $mb_factory = module_builder_get_factory('ModuleBuilderEnvironmentDrush');
         $mb_task_handler_report_plugins = $mb_factory->getTask('ReportPluginData');
         $options = $mb_task_handler_report_plugins->listPluginNamesOptions();
         return $options;
     }, 'component' => 'Plugin'), 'settings_form' => array('label' => "Admin settings form", 'required' => FALSE, 'format' => 'boolean', 'component' => 'AdminSettingsForm'), 'router_items' => array('label' => "required router paths, eg 'path/foo'", 'required' => FALSE, 'format' => 'array', 'component' => 'RouterItem'), 'module_camel_case_name' => array('computed' => TRUE, 'default' => function ($component_data) {
         $pieces = explode('_', $component_data['module_root_name']);
         $pieces = array_map('ucfirst', $pieces);
         return implode('', $pieces);
     }));
     return $component_data_definition;
 }
コード例 #10
0
<?php

$sql = "select t5.tid, d1.name as l1, d2.name as l2, d3.name as l3, d4.name as l4, d5.name as l5 from {taxonomy_term_hierarchy} t1 inner join {taxonomy_term_hierarchy} t2 on t2.parent = t1.tid inner join {taxonomy_term_hierarchy} t3 on t3.parent = t2.tid inner join {taxonomy_term_hierarchy} t4 on t4.parent = t3.tid inner join {taxonomy_term_hierarchy} t5 on t5.parent = t4.tid  inner join taxonomy_term_data d5 on d5.tid = t5.tid inner join taxonomy_term_data d4 on d4.tid = t4.tid  inner join taxonomy_term_data d3 on d3.tid = t3.tid inner join taxonomy_term_data d2 on d2.tid = t2.tid inner join taxonomy_term_data d1 on d1.tid = t1.tid limit 100;";
$result = db_query($sql);
$data = $result->fetchAllAssoc('tid');
$output = array();
foreach ($data as $row) {
    $nids = taxonomy_select_nodes($row->tid, FALSE);
    if ($nids) {
        drush_log('Fixing ' . $row->tid . ': ' . $row->l1 . ' > ' . $row->l2 . ' > ' . $row->l3 . ' > ' . $row->l4 . ' > ' . $row->l5);
        $parent = taxonomy_get_parents($row->tid);
        $parent_id = reset(array_keys($parent));
        $nids = array_unique($nids);
        drush_print_r($nids);
        $nodes = node_load_multiple($nids);
        foreach ($nodes as $node) {
            if (isset($node->field_locations)) {
                foreach ($node->field_locations as $lang => $items) {
                    $parent_found = FALSE;
                    foreach ($items as $i => $item) {
                        // Check if parent exists.
                        if ($item['target_id'] == $parent_id) {
                            $parent_found = TRUE;
                        }
                    }
                    if ($parent_found) {
                        // Remove child.
                        foreach ($items as $i => $item) {
                            if ($item['target_id'] == $row->tid) {
                                unset($node->field_locations[$lang][$i]);
                                break;