Example #1
0
 function _admin_user_role_op($role_machine_name, $op)
 {
     // c.f. http://drupal.org/node/283261
     require_once drupal_get_path('module', 'user') . "/user.admin.inc";
     $form_id = "user_admin_new_role";
     $form_values = array();
     $form_values["name"] = $role_machine_name;
     $form_values["op"] = $op;
     $form_state = array();
     $form_state["values"] = $form_values;
     drupal_execute($form_id, $form_state);
 }
function covidien_contenttype_update($arg) {
  module_load_include('inc', 'content', 'includes/content.crud');

  $module_name = $arg['module_name'];
  $import_new = $arg['import_new'];
  $import_updatearr = $arg['import_updatearr'];
  $import_deletearr = $arg['import_deletearr'];
  $import_ctdeletearr = $arg['import_ctdeletearr'];

  $import_update = array_keys($import_updatearr);

  $files = file_scan_directory(drupal_get_path('module', $module_name) . '/content_type', '.cck_import.inc');
  if (is_array($import_ctdeletearr) && count($import_ctdeletearr) > 0) {
    foreach ($import_ctdeletearr as $key => $fields) {
      if (count($fields) > 0) {
        foreach ($fields as $field_name) {
          $field = array();
          $field['field_name'] = $field_name;
          $field['type_name'] = $key;
          content_field_instance_delete($field['field_name'], $field['type_name'], FALSE);
          drupal_set_message('Deleted ' . $field['field_name'] . ' in ' . $field['type_name']);
        }
      }
    }
    // Clear caches and rebuild menu.
    content_clear_type_cache(TRUE);
    menu_rebuild();
  }
  foreach ($files as $absolute => $file) {
    // Creating new content type.
    if (in_array($file->name, $import_new)) {
      $form_state = array();
      $form_state['values']['type_name'] = '<create>';
      $fh = fopen($file->filename, 'r');
      $theData = fread($fh, filesize($file->filename));
      fclose($fh);
      $form_state['values']['macro'] = "$theData";
      drupal_execute('content_copy_import_form', $form_state);
    }

    // Updating existing content type.	
    if (in_array($file->name, $import_update)) {
      // Add the new fileds to the content type
      $form_state = array();
      $form_state['values']['type_name'] = $import_updatearr[$file->name];
      $fh = fopen($file->filename, 'r');
      $theData = fread($fh, filesize($file->filename));
      eval($theData);
      fclose($fh);
      $form_state['values']['macro'] = "$theData";
      drupal_execute('content_copy_import_form', $form_state);
      // Update Title filed label
      $title_label = $content['type']['title_label'];
      $type = $content['type']['type'];
      db_query("UPDATE {node_type} SET title_label = '%s' WHERE type = '%s'", $title_label, $type);
      // Update several fields at a time.	  
      if (count($content['fields']) > 0) {
        foreach ($content['fields'] as $key => $field) {
          if (is_array($field)) {
            $field['type_name'] = $content['type']['type'];
            if ($field['type_name'] != '' && $field['field_name'] != '') {
              content_field_instance_update($field, FALSE);
              drupal_set_message('updated ' . $field['field_name'] . ' in ' . $field['type_name']);
            }
          }
        }
      }

      /**
       * Code to remove the cck filed from content type.
       */
      if (is_array($import_deletearr)) {
        $fields = $import_deletearr[$file->name];
      }
      if (count($fields) > 0) {
        foreach ($fields as $field_name) {
          $field = array();
          $field['field_name'] = $field_name;
          $field['type_name'] = $import_updatearr[$file->name];
          content_field_instance_delete($field['field_name'], $field['type_name'], FALSE);
          drupal_set_message('Deleted ' . $field['field_name'] . ' in ' . $field['type_name']);
        }
      }

      // Clear caches and rebuild menu.
      content_clear_type_cache(TRUE);
      menu_rebuild();
    }
  }
}
 /**
  * Disables a drupal module in the test database.
  *
  * @param string $name Name of the module.
  * @return boolean Success.
  * @see drupalModuleEnable()
  */
 function drupalModuleDisable($name)
 {
     if (!module_exists($name)) {
         $this->pass(" [module] {$name} already disabled");
         return TRUE;
     }
     unset($this->_modules[$key]);
     $form_state['values'] = array('status' => $this->_modules, 'op' => t('Save configuration'));
     drupal_execute('system_modules', $form_state);
     //rebuilding all caches
     drupal_rebuild_theme_registry();
     node_types_rebuild();
     menu_rebuild();
     cache_clear_all('schema', 'cache');
     module_rebuild_cache();
 }
Example #4
0
 /**
  * Slightly change the default signature, in order to pragmatically add the
  * content type name in order to use it as update function.
  * 
  * Because content types won't have a changing name among sites (on the
  * opposite as other entities which has incremented identifiers instead
  * of user set canonical name) we can afford to do an intelligent function
  * that will guess itself whatever it has to do.
  * 
  * @see Entity::_save()
  */
 protected function _save($export, $type_name = NULL)
 {
     // Basic behavior options.
     $overwrite = FALSE;
     switch ($this->getSettings()->getOption('contentBehavior', Yamm_Entity_ContentSettings::MODULE_OVERRIDE)) {
         case Yamm_Entity_ContentSettings::MODULE_IGNORE:
             return;
         case Yamm_Entity_ContentSettings::MODULE_OVERRIDE:
             // Let the algorigthm do its default job, which is saving the current
             // content type whatever it exists or not.
             $overwrite = TRUE;
             break;
         case Yamm_Entity_ContentSettings::MODULE_OVERRIDEFALLBACK:
             // FIXME: Todo.
             break;
         case Yamm_Entity_ContentSettings::MODULE_TRYENABLE:
         default:
             // FIXME: Todo.
             break;
     }
     // Get back content type name.
     if (!$type_name) {
         preg_match('/\'type\'[ ]+=>[ ]+\'([a-zA-Z0-9-_]+)\'/', $export, $matches);
         $type_name = $matches[1];
     }
     // Check that type already exists on client side, if yes, overwrite it.
     $type_exists = db_result(db_query("SELECT 1 FROM {node_type} WHERE name = '%s'", $type_name));
     $values = array('macro' => $export, 'op' => 'Submit');
     $values['type_name'] = $type_exists ? $type_name : '<create>';
     // Save the content type using the content_copy module.
     $form_state['values'] = $values;
     drupal_execute('content_copy_import_form', $form_state);
     // Check for errors during creation or update.
     if ($errors = form_get_errors()) {
         foreach ($errors as $error) {
             $msg .= "{$error} ";
         }
         watchdog('entity_content', "Error during content import @msg", array("@msg" => $msg), WATCHDOG_ERROR);
     }
     // Attempt to clear form cache.
     cache_clear_all(NULL, 'cache_form');
     form_set_error(NULL, '', TRUE);
     // This will store content type latest definition.
     cache_set('content_entity_' . $type_name, md5($export), 'yamm_data_store', CACHE_PERMANENT);
     return $type_name;
 }
Example #5
0
 /**
  * Function to create a user in Drupal.
  *  
  * @param array  $params associated array 
  * @param string $mail email id for cms user
  *
  * @return uid if user exists, false otherwise
  * 
  * @access public
  * @static
  */
 static function createDrupalUser(&$params, $mail)
 {
     $values['values'] = array('name' => $params['cms_name'], 'mail' => $params[$mail], 'op' => 'Create new account');
     if (!variable_get('user_email_verification', TRUE)) {
         $values['values']['pass']['pass1'] = $params['cms_pass'];
         $values['values']['pass']['pass2'] = $params['cms_pass'];
     }
     $config =& CRM_Core_Config::singleton();
     // we also need to redirect b
     $config->inCiviCRM = true;
     $res = drupal_execute('user_register', $values);
     $config->inCiviCRM = false;
     if (form_get_errors()) {
         return false;
     }
     // looks like we created a drupal user, lets make another db call to get the user id!
     $db_cms = DB::connect($config->userFrameworkDSN);
     if (DB::isError($db_cms)) {
         die("Cannot connect to UF db via {$dsn}, " . $db_cms->getMessage());
     }
     //Fetch id of newly added user
     $id_sql = "SELECT uid FROM {$config->userFrameworkUsersTableName} where name = '{$params['cms_name']}'";
     $id_query = $db_cms->query($id_sql);
     $id_row = $id_query->fetchRow(DB_FETCHMODE_ASSOC);
     return $id_row['uid'];
 }
system_modules_submit(NULL, $form_state);
unset($form_state);
// Run cron after installing
drupal_cron_run();
// Create new content types.
module_load_include('inc', 'node', 'content_types');
$form_state = array('values' => array());
$form_state['values']['name'] = 'test-group';
$form_state['values']['type'] = 'test_group';
$form_state['values']['og_content_type_usage'] = 'group';
drupal_execute('node_type_form', $form_state);
$form_state = array('values' => array());
$form_state['values']['name'] = 'test-post-group';
$form_state['values']['type'] = 'test_post_group';
$form_state['values']['og_content_type_usage'] = 'group_post_standard';
drupal_execute('node_type_form', $form_state);
// Create users with ID 3 to 7.
$user_ids = array();
foreach (range(3, 7) as $i) {
    $user_values = array();
    $user_values['name'] = 'og_test_user' . $i;
    $user_values['mail'] = 'og_test_user' . $i . '@example.com';
    $user_values['pass'] = user_password(5);
    $user_values['status'] = 1;
    $user = user_save(NULL, $user_values);
    $user_ids[$i] = $user->uid;
}
/**
 * Organic groups content generation interface.
 */
interface ogContent
Example #7
0
 /**
  * @param $overrides includes values for any fields that should not
  * come from the user or user's member profile
  */
 public function createFromUser($account, $overrides = array())
 {
     global $user;
     $values = $overrides;
     $values['type'] = $this->name;
     $values['name'] = isset($user->name) ? $user->name : '';
     $values['language'] = '';
     if (is_object($account)) {
         $values['cuid'] = $account->uid;
     } else {
         $values['cuid'] = $account;
     }
     $form_state = array('values' => $values);
     $form_state['values']['op'] = t('Save');
     module_load_include("inc", "node", "node.pages");
     // call drupal_execute with the form values filled in by the
     // proxy modules for this node type
     drupal_execute('contributor_node_form', $form_state, (object) $values);
     if (isset($form_state['nid'])) {
         return $form_state['nid'];
     } else {
         return FALSE;
     }
 }
Example #8
0
<?php

global $user;
tzbase_include_proto_classes();
$account = user_load(array('name' => 'Johan Heander'));
if ($account) {
    TZIntellitimeBot::destroy_session_data($account->intellitime_session_data);
    user_save($account, array('intellitime_session_data' => NULL));
}
// Login and logout to refresh cookie
$form_state = array('values' => array('name' => 'Johan Heander', 'pass' => '0733623516', 'op' => t('Log in')));
drupal_execute('user_login', $form_state);
// Destroy the current session:
session_destroy();
// Only variables can be passed by reference workaround.
$null = NULL;
user_module_invoke('logout', $null, $user);
// Load the anonymous user
$user = drupal_anonymous_user();
tzintellitime_sync_synchronize_users();
TZIntellitimeBot::destroy_session_data($account->intellitime_session_data);
/**
 * Add issue files.
 */
function merci_import_1()
{
    // This determines how many content types will be created per page load.
    // A resonable default has been chosen, but feel free to tweak to suit your needs.
    $limit = 10;
    // No file uploaded, so skip the import.
    if (!$_SESSION['content_types_file']) {
        return array();
    }
    // Multi-part import.
    if (!isset($_SESSION['merci_import_1'])) {
        $csv_file_array = file($_SESSION['content_types_file']);
        $_SESSION['merci_import_file_position'] = 0;
        $_SESSION['merci_import_1'] = 0;
        $_SESSION['merci_import_1_max'] = count($csv_file_array) - 1;
    }
    // Open import file.
    $handle = fopen($_SESSION['content_types_file'], 'r');
    fseek($handle, $_SESSION['merci_import_file_position']);
    // Have to manually load the content types inc file.
    module_load_include('inc', 'node', 'content_types');
    $ret = array();
    $count = 0;
    while (($data = fgetcsv($handle)) !== FALSE) {
        $count++;
        $_SESSION['merci_import_1']++;
        // Only save if the row count for the data is right.
        if (count($data) == 13) {
            // Node type settings.
            $form_state['values']['orig_type'] = '';
            $form_state['values']['type'] = $data[0];
            $form_state['values']['name'] = $data[1];
            $form_state['values']['description'] = $data[2];
            $form_state['values']['help'] = $data[3];
            $form_state['values']['min_word_count'] = 0;
            $form_state['values']['title_label'] = t('Title');
            $form_state['values']['body_label'] = t('Body');
            $form_state['values']['custom'] = TRUE;
            $form_state['values']['locked'] = FALSE;
            $form_state['values']['node_options'] = array('promote' => 0, 'revision' => 1, 'status' => 1, 'sticky' => 0);
            // MERCI settings.
            $form_state['values']['merci_type_setting'] = $data[4];
            $form_state['values']['merci_max_hours_per_reservation'] = $data[5];
            $form_state['values']['merci_allow_overnight'] = $data[6];
            $form_state['values']['merci_allow_weekends'] = $data[7];
            $form_state['values']['merci_late_fee_per_hour'] = $data[8];
            $form_state['values']['merci_rate_per_hour'] = $data[9];
            $form_state['values']['merci_fee_free_hours'] = $data[10];
            $form_state['values']['merci_status'] = $data[11];
            $form_state['values']['merci_spare_items'] = $data[0] == 'bucket' ? $data[12] : 0;
            $form_state['clicked_button']['#value'] = t('Save content type');
            drupal_execute('node_type_form', $form_state);
        }
        // Jump out of the loop here and do another cycle.  Save
        // where we're at in the CSV file.
        if ($count >= $limit) {
            $_SESSION['merci_import_file_position'] = ftell($handle);
            break;
        }
    }
    // No more lines in the file, import is done.  Clean up.
    if (!fgets($handle)) {
        fclose($handle);
        unset($_SESSION['merci_import_file_position']);
        unset($_SESSION['merci_import_1']);
        unset($_SESSION['merci_import_1_max']);
        file_delete($_SESSION['content_types_file']);
        unset($_SESSION['content_types_file']);
        return $ret;
    }
    fclose($handle);
    $ret['#finished'] = $_SESSION['merci_import_1'] / $_SESSION['merci_import_1_max'];
    return $ret;
}
Example #10
0
 /**
  * tearDown implementation, setting back switched modules etc
  */
 function tearDown()
 {
     if ($this->_modules != $this->_originalModules) {
         $form_state['values'] = array('status' => $this->_originalModules, 'op' => t('Save configuration'));
         drupal_execute('system_modules', $form_state);
         //rebuilding all caches
         drupal_rebuild_theme_registry();
         node_types_rebuild();
         menu_rebuild();
         cache_clear_all('schema', 'cache');
         module_rebuild_cache();
         $this->_modules = $this->_originalModules;
     }
     foreach ($this->_cleanupVariables as $name => $value) {
         if (is_null($value)) {
             variable_del($name);
         } else {
             variable_set($name, $value);
         }
     }
     $this->_cleanupVariables = array();
     //delete nodes
     foreach ($this->_cleanupNodes as $nid) {
         node_delete($nid);
     }
     $this->_cleanupNodes = array();
     //delete roles
     while (sizeof($this->_cleanupRoles) > 0) {
         $rid = array_pop($this->_cleanupRoles);
         db_query("DELETE FROM {role} WHERE rid = %d", $rid);
         db_query("DELETE FROM {permission} WHERE rid = %d", $rid);
     }
     //delete users and their content
     while (sizeof($this->_cleanupUsers) > 0) {
         $uid = array_pop($this->_cleanupUsers);
         // cleanup nodes this user created
         $result = db_query("SELECT nid FROM {node} WHERE uid = %d", $uid);
         while ($node = db_fetch_array($result)) {
             node_delete($node['nid']);
         }
         user_delete(array(), $uid);
     }
     //delete content types
     foreach ($this->_cleanupContentTypes as $type) {
         node_type_delete($type);
     }
     $this->_cleanupContentTypes = array();
     //Output drupal warnings and messages into assert messages
     $drupal_msgs = drupal_get_messages();
     foreach ($drupal_msgs as $type => $msgs) {
         foreach ($msgs as $msg) {
             $this->assertTrue(TRUE, "{$type}: {$msg}");
         }
     }
     parent::tearDown();
 }
Example #11
0
 /**
  * Creates the given importer configuration
  *
  * @param $name
  *   Name for the importer
  * @param $type
  *   Name of the content-type
  */
 private function createImporter($name, $type)
 {
     $status = module_load_include('inc', 'feeds_ui', 'feeds_ui.admin');
     if ($status === FALSE) {
         throw new Exception("Feeds UI is not installed. Please enable it before trying to migrate.");
     }
     $form_state = array();
     $form_state['values']['id'] = $form_state['values']['name'] = $name;
     $form_state['values']['description'] = 'From ' . $type . ' FeedAPI content-type by the FeedAPI2Feeds migration script.';
     $form_state['values']['op'] = t('Create');
     drupal_execute('feeds_ui_create_form', $form_state);
 }