Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file entitycache.drush.inc
- * drush integration for entitycache.
- * Simple idea - load each of the entities.
- * @TODO: Figure out how to do it in batches.
- * @TODO: Figure out how to only load entities not yet in cache.
- * @TODO: Figure out a way to have it done via a scheduler.
- */
- /**
- * Implementation of hook_drush_help().
- */
- function entitycache_drush_help($section) {
- switch ($section) {
- case 'drush:entity-load-cache':
- return dt('Used without parameters, this command loads all the various objects in the entities into cache using entity_load()');
- }
- }
- /**
- * Implementation of hook_drush_command().
- */
- function entitycache_drush_command() {
- $items = array();
- $items['entitycache-load-cache'] = array(
- 'callback' => 'drush_entitycache_load_cache',
- 'description' => t('Load the cache with the various entities configured to use the cache'),
- 'arguments' => array(
- 'type' => dt('Optional. Only load the particular entity type objects into cache'),
- ),
- 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
- 'aliases' => array('elc'),
- );
- return $items;
- }
- /**
- * Load the cache bin with content from the various entities.
- * @param $type Optional. The specific type of entity that should
- * get it's content cached.
- */
- function drush_entitycache_load_cache($type = '') {
- $types = entitycache_supported_core_entities(TRUE);
- $start = time();
- if (!empty($type)) {
- if (!isset($types[$type])) {
- drush_die("Type $type is not supported");
- }
- else {
- _drush_entitycache_load_cache($type);
- }
- }
- else {
- foreach ($types as $entity_type => $entity_controller) {
- _drush_entitycache_load_cache($entity_type);
- }
- }
- drush_print("Caching complete!");
- drush_print("Total processing time: ". (time() - $start) ." seconds.");
- }
- /**
- * Load the cache bin with content from a specific type of entity.
- */
- function _drush_entitycache_load_cache($type) {
- $max_limit = 50;
- drush_print("Begin caching $type");
- $query = new EntityFieldQuery;
- $result = $query
- ->entityCondition('entity_type', $type)
- ->execute();
- $keys = array();
- $limit = 0;
- foreach ($result[$type] as $entity_key => $entity_info) {
- $keys[] = $entity_key;
- $limit++;
- if ($limit >= $max_limit) {
- entity_load($type, $keys, array(), TRUE);
- $keys = array();
- $limit = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement