Tagged: drupal

missing_leg_session.diff

missing_leg_session.diff
diff --git a/docroot/sites/all/modules/custom/cga_legislators/cga_legislators.module b/docroot/sites/all/modules/custom/cga_legislators/cga_legislators.module
index 394d474..503a3e9 100644
--- a/docroot/sites/all/modules/custom/cga_legislators/cga_legislators.module
+++ b/docroot/sites/all/modules/custom/cga_legislators/cga_legislators.module
@@ -41,6 +41,7 @@ function cga_legislators_block_view($delta = '') {
       $committees = array();
       $committees['role'] = array();
       $committees['no_role'] = array();
+      $current_sess = cga_entity_queries_get_current_or_most_recent_session();
       foreach ($relations as $relation) {
         $wrapper = entity_metadata_wrapper('relation', $relation);
         $endpoints = $wrapper->endpoints->value();
@@ -53,6 +54,11 @@ function cga_legislators_block_view($delta = '') {
         foreach ($endpoints as $node) {
           if ($node->type->value() != 'legislator') {
             $w = entity_metadata_wrapper('node', $node);
+            // Check if committee is in the current session, if not, do not show on the legislator page.
+            $committee_sess = $w->field_session->value();
+            if($current_sess->tid != $committee_sess->tid) {
+              continue;
+            }
             // Add to committees array only if this committee is toggled for display
             if($w->field_display_on_member_page->value() == 1) {
               if (!empty($role)) {

Disable Search API index running on Dev and Stage servers on Acquia

disable_search_indexing_on_non_prod.php
<?php
/**
 * ENV AH_NON_PRODUCTION is set on dev and test on 
 *   acquia servers but not local servers.
 */
function cga_utility_search_api_index_load($indexes) {
  if( isset($_ENV['AH_NON_PRODUCTION']) ) {
    foreach ($indexes as &$index) {
      $index->read_only = "1";
    }
  }
}

Create Calendar PDF Queue Item.

create_cal_pdf.php
<?php

class NodeHouseCommitteeScheduleItemQueue extends ImportQueue {

  public function request($reset = FALSE, $pdf_request = FALSE) {
    parent::request($reset);

    if (!$pdf_request) {
      if (!empty($this->data->events)) {
        $this->data = $this->data->events;
      }
    } else {
      $this->data = $this->data->calendar_pdf;
    }
  }

  public function executeCronQueue() {
     // [deleted unnecessary code... ]
  
      //Need to pull across the schedule item PDF.
      $this->request(FALSE, TRUE);
      $url = $this->data;
      $cal_bean = bean_load(36);
      $bean_wrapper = entity_metadata_wrapper('bean', $cal_bean);
      $file_info = system_retrieve_file($url, 'public://', TRUE, FILE_EXISTS_REPLACE);
      if (!empty($file_info)) {
        $bean_wrapper->field_house_calendar->file->set($file_info);
        $bean_wrapper->save();
      }
      return parent::executeCronQueue(); // TODO: Change the autogenerated stub
  }
}

Mass update nodes in drupal

mass_update_nodes_devel.php
<?php
module_load_include('inc', 'node', 'node.admin');
$nids = db_query("SELECT nid FROM {node} where type = 'bill' ")->fetchCol();

// Update in batches
$start = 0;
$batch_size = 10;
$nids = array_slice($nids, $start, $batch_size);
node_mass_update($nids, array());

cga_entity_query.diff

cga_entity_query.diff
diff --git a/docroot/sites/all/modules/custom/cga_entity_queries/cga_entity_queries.module b/docroot/sites/all/modules/custom/cga_entity_queries/cga_entity_queries.module
index a1c029b..dafb76c 100644
--- a/docroot/sites/all/modules/custom/cga_entity_queries/cga_entity_queries.module
+++ b/docroot/sites/all/modules/custom/cga_entity_queries/cga_entity_queries.module
@@ -354,6 +354,7 @@ function cga_entity_queries_get_current_or_most_recent_session() {
       $query = new EntityFieldQuery();
       $query->entityCondition('entity_type', 'taxonomy_term')
         ->entityCondition('bundle', 'sessions')
+        ->fieldCondition('field_start_end_dates', 'value', date("Y-m-d"), '<=')
         ->fieldOrderBy('field_start_end_dates', 'value2', 'DESC')
         ->range(0, 1)
         ->addMetaData('account', user_load(1)); // Run the query as user 1.
@@ -801,4 +802,4 @@ function cga_entity_queries_get_detail_pages_by_committee($comm_nid) {
     return $node;
   };
   return cga_utility_query_cache(__FUNCTION__, $query, "{$comm_nid}");
-}
\ No newline at end of file
+}

Delete a bunch of taxonomy terms

del_tax.php
<?php
$tids = taxonomy_get_term_by_name("Withdrawn Prior to R&C Hearing");
// Drop the first one (this has the initiatives attached to it).
array_shift($tids);
dpm(array_values($tids));
$all = array();
foreach (array_values($tids) as $tax) {
  print "deleting $tax->tid";
  $all[] = $tax->tid;
  taxonomy_term_delete($tax->tid);
}
// OR to delete blank taxonomy terms (blank session)
$tids = taxonomy_get_term_by_name("");
// Drop the first one (this has the initiatives attached to it).
array_shift($tids);
dpm(array_values($tids));
$all = array();
foreach (array_values($tids) as $tax) {
  print "deleting $tax->tid";
  $all[] = $tax->tid;
  taxonomy_term_delete($tax->tid);
}