Skip to content

Instantly share code, notes, and snippets.

@arturo-c
Created July 25, 2013 16:00
Show Gist options
  • Save arturo-c/6081202 to your computer and use it in GitHub Desktop.
Save arturo-c/6081202 to your computer and use it in GitHub Desktop.
/**
* Class that uses basic perform function to process queued jobs.
*/
class CopyGroupHierarchy
{
/**
* Before processing, connect to correct instance of redis.
*/
public function __construct()
{
// include dirname(__DIR__) . '/config/config.php';
if (isset($config['redis_password']) && !$config['redis_password'] == '') {
Resque::setBackend('redis://redis:' . $config['redis_password'] . '@' . $config['redis_host']);
}
define('DRUPAL_ROOT', '/mnt/apci/main/www');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_USER_AGENT'] = 'RESQUE_WORKER';
chdir(DRUPAL_ROOT);
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
}
/**
* Perform the post operations.
*/
public function perform()
{
$clone_map = variable_get('clone_map', array());
global $user;
$user = user_load(1);
$node = node_load($this->args['gid']);
module_load_include('inc', 'services', 'services.runtime');
$web_address = strtolower(preg_replace('/(?:\W+|_{2,})/', '_', $node->title)) . '-' . (string) $node->nid;
$clone = GroupResource::create($node->title, $node->og_description, array('zip' => $node->field_location[0]['postal_code']), array(0 => 'Sports'), 'team', $web_address);
$clone = node_get_by_uuid($clone['uuid']);
$clone_map[$node->nid] = $clone->nid;
$clone->field_group = $node->field_group;
node_save($clone);
variable_del('purl_method_spaces_og');
variable_del('purl_method_spaces_og_key');
GroupResource::copy($clone->uuid, $node->uuid);
variable_set('clone_map', $clone_map);
resque_queue('CloneGroupHierarchy', array('parent' => $this->args['parent'], 'gid' => $this->args['gid'], 'options' => $this->args['options']));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment