1
votes

I've taken over managing our site from MIA developers and have spent the day trying to find this answer.

After upgrading to v 7.56 there's just ONE specific page in a list of pages that I am unable to access as an admin. (and unfortunately it's probably the most needed report in our admin panel).

Here's what I know:

  • Drupal Version 7.56
  • PHP 7.0.20
  • No errors when status report is run
  • Chron - no errors

Here's what I've done:

  1. added $cookie_domain = '.example.com'; to settings.php
  2. cleared browser cache and cookies
  3. ensured admin has access to everything
  4. cleared site cache
  5. made sure code on page(s) was exactly the same as it was before I did the update

Not sure what to do or where to go from here. Any help is much appreciated.

UPDATE: When logged in as super admin, received HTTP 500 error. After more research, I updated the php.ini to include memory_limit = 64M ; Now I can view the page as the superadmin, but it still isn't available for other admins.

Image 1: viewing page as admin

Image 2: viewing page as superadmin

function custom_reports_menu() {

    $items['administration/upcoming-classes'] = array(
    'title' => 'Upcoming Classes',
    'page callback' => 'custom_reports_upcoming_classes_page',
    'access callback' => 'user_access',
    'access arguments' => array('admin wdcc reports'),
        'file' => 'includes/custom_reports.upcoming-classes.inc',
    'type' => MENU_CALLBACK,
    );

    $items['administration/class-details'] = array(
    'title' => 'Class Details',
    'page callback' => 'custom_reports_class_details_page',
    'access callback' => 'user_access',
    'access arguments' => array('admin wdcc reports'),
        'file' => 'includes/custom_reports.class-details.inc',
    'type' => MENU_CALLBACK,
    );
    return $items;

}

function custom_reports_upcoming_classes_page() {

    drupal_add_css(base_path().path_to_theme().'/assets/css/outburst-accounts.css', array('type' => 'external'));

    global $user;
    $uid = $user->uid;

    $output = '';

    $upcoming_classes = custom_reports_get_upcoming_classes();
    $attendee_count = custom_reports_get_attendee_count();

    // upcoming classes
    $output .= '<h2>Upcoming Classes</h2>';
    $output .= custom_reports_format_upcoming_classes($upcoming_classes, $attendee_count);

    return $output;
}

function custom_reports_permission() {

  return array(
    'admin wdcc reports' => array(
      'title' => t('Admin WDCC Reports'),
      'description' => t('Perform administration tasks for WDCC.'),
      //'cache' => DRUPAL_NO_CACHE,
    ),
  );
}

function custom_reports_get_upcoming_classes() {

    $today = date('Y-m-d');

    $x = 0;
    $classes = '';

    // get classes from new db tables
    $today = date('Y-m-d H:i:s');

    $result = db_query("SELECT n.nid FROM node n, field_data_field_date fdfd WHERE n.status = :status AND n.type = :type AND n.nid = fdfd.entity_id AND fdfd.field_date_value >= :today ORDER BY fdfd.field_date_value ASC", array(':status' => 1, ':type' => 'public_class_date', ':today' => $today));
    if ($result->rowCount() > 0) {
        foreach ($result as $row) {

            $nid = $row->nid;
            $node = node_load($nid);

            $product_id = $nid;
            $product_title = $node->title;
            $product_type = 'public_class_date';
            $product_date = $node->field_date[$node->language][0]['value'];
            $product_datestamp = strtotime($product_date);
            //$product_datestamp = strtotime($product_date);

            // set vars
            $classes[$x]['product_id'] = $product_id;
            $classes[$x]['product_title'] = $product_title;
            $classes[$x]['product_type'] = $product_type;
            $classes[$x]['product_date'] = $product_date;
            $classes[$x]['product_datestamp'] = $product_datestamp;

            $x++;
        }
    }

    return $classes;
}

function custom_reports_get_attendee_count() {

    $attendees = array();
    $old_attendees = array();
    $new_attendees = array();

    $result = db_query("SELECT itemID, attendeeID, attendeeName FROM wdcc_old_attendee");
    if ($result->rowCount() > 0) {
        foreach ($result as $row) {
            $item_id = $row->itemID;
            $attendee_id = 'B'.$row->attendeeID;
            $attendee_name = $row->attendeeName;

            $old_attendees[$item_id][$attendee_id]['old_attendee_id'] = $attendee_id;

            if (strpos($attendee_name, '&') > 0 || strpos($attendee_name, ' and') > 0) { // couples
                $old_attendees[$item_id][$attendee_id]['total_attendees'] = 2;
            } else {
                $old_attendees[$item_id][$attendee_id]['total_attendees'] = 1;
            }
        }
    }
    if (is_array($old_attendees)) {
        $connect_class_ids = custom_accounts_connect_class_ids();
        foreach ($old_attendees as $old_item_id => $attendee_list) {
            if (isset($connect_class_ids[$old_item_id])) {
                $product_id = $connect_class_ids[$old_item_id];
                foreach ($attendee_list as $attendee_id => $attendee) {
                    $old_attendee_id = $attendee['old_attendee_id'];
                    $attendees[$product_id][$old_attendee_id]['total_attendees'] = $attendee['total_attendees'];
                }
            }
        }
    }
    $result = db_query("SELECT id, product_id FROM wdcc_attendees WHERE transaction_id > 0");
    if ($result->rowCount() > 0) {
        foreach ($result as $row) {
            $attendee_id = $row->id;
            $product_id = $row->product_id;
            $attendees[$product_id][$attendee_id]['total_attendees'] = 1;
        }
    }
    $cancelled_attendees = array();
    $result = db_query("SELECT * FROM wdcc_attendees_cancelled");
    if ($result->rowCount() > 0) {
        foreach ($result as $row) {
            $attendee_id = $row->attendee_id;
            $old_attendee_id = 'B'.$row->old_attendee_id;

            if ($attendee_id > 0) {
                $cancelled_attendees[] = $attendee_id;
            } else {
                $cancelled_attendees[] = $old_attendee_id;
            }
        }
    }
    foreach ($attendees as $product_id => $product_attendees) {
        foreach ($product_attendees as $attendee_id => $attendee) {
            if (in_array($attendee_id, $cancelled_attendees)) {
                unset($attendees[$product_id][$attendee_id]);
            }
        }
    }
    $attendee_count = array();
    foreach ($attendees as $product_id => $product_attendees) {
        foreach ($product_attendees as $attendee_id => $attendee) {
            if (!isset($attendee_count[$product_id])) {
                $attendee_count[$product_id] = $attendee['total_attendees'];
            } else {
                $attendee_count[$product_id] = $attendee_count[$product_id] + $attendee['total_attendees'];
            }
        }
    }

    return $attendee_count;
}

function custom_reports_format_upcoming_classes($upcoming_classes, $attendee_count) {

    $output = '';

    if (is_array($upcoming_classes)) {
        $output .= '<div class="table-responsive table-container">';
        $output .= '<table class="table">';
        $output .= '<tr><td>Class</td><td>Guests</td><td>Actions</td></tr>';
        foreach ($upcoming_classes as $class) {
            $nid = $class['product_id'];
            $node_url = url('node/'.$nid, array('absolute' => TRUE));
            $attendees = 0;
            if (isset($attendee_count[$nid])) {
                $attendees = $attendee_count[$nid];
            }

            $output .= '<tr><td><a href="'.$node_url.'">'.$class['product_title'].'</a><br />'.date('m/d/Y - g:i A', $class['product_datestamp']).'</td><td>'.$attendees.'</td><td><a href="/administration/class-details/'.$class['product_id'].'">View roster</a></td></tr>';
        }
        $output .= '</table>';
        $output .= '</div>';
    } else {
        $output .= '<p>No upcoming classes found.</p>';
    }

    return $output;
}
3
I am able to access your callbacks from my custom module, did you check if any php errors in your code (check apache error.log) and enable "All messages" in admin/config/development/logging - Viswanath Polaki
are you accessing administration/upcoming-classes rather than admin/upcoming-classes - Viswanath Polaki
So yesterday I was getting these: PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 696320 bytes) in ..../public_html/includes/database/database.inc on line 2227 - Changing the php.ini to 128M seemed to stop those - Kathryn

3 Answers

0
votes

Probably would need more info, but it seems like a case of custom or hardcoded permissions.

Here's potential cases to explore:

  • Assign all the roles to the admin user
  • Search custom modules for this page URL. See if page is only certain users are allowed to access this page.
  • If report is Drupal View, find this view and check the permissions section.
0
votes

In the current menu items you are using access callback attribute in a wrong way. Your menu items do not require to specify access callback. Only access argument is sufficient.

Please add an access argument to which only admin has access.

"access callback": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user_access() unless a value is inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks. To use the user_access() default callback, you must specify the permission to check as 'access arguments' (see below).

Source: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x

0
votes

Replace this below code in settings.php file

PHP variable name:

$cookie_domain = 'example.com'; (line 340)