Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/7.x-1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangrynenko committed Feb 6, 2016
2 parents c6a4880 + 2acad02 commit 905df39
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 23 deletions.
18 changes: 13 additions & 5 deletions classes/XsVm.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function getVbds() {
* @return array
* Snapshot array.
*/
protected function setSnapshots() {
protected function setSnapshots($reorder_asc) {
$this->getData();

if (!empty($this->data['snapshots'])) {
Expand All @@ -457,11 +457,19 @@ protected function setSnapshots() {
}
}

$this->snapshots = $this->snapshotsReorder($full_snapshots);
$this->snapshots = $this->snapshotsReorder($full_snapshots, $reorder_asc);
}

public function getSnapshots() {
$this->setSnapshots();
/**
* Gets snapshots via XenApi.
*
* @param bool $reorder_asc
* Reorder snapshots ascending.
*
* @return mixed
*/
public function getSnapshots($reorder_asc = FALSE) {
$this->setSnapshots($reorder_asc);

return $this->snapshots;
}
Expand All @@ -476,7 +484,7 @@ public function getSnapshots() {
* @return array
* Reordered snapshots.
*/
protected function snapshotsReorder($snapshots, $ascending = FALSE) {
public function snapshotsReorder($snapshots, $ascending = FALSE) {
if (empty($snapshots)) {
return $snapshots;
};
Expand Down
8 changes: 4 additions & 4 deletions modules/xs_snapshot_policy/tests/xs_snapshot_policy.test
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,20 @@ class XenServerSnapshotPolicyTestCase extends XenServerTestCase {
));
$this->drupalLogin($user);

$this->drupalGet('admin/structure/xs/snapshot-policy-types/add');
$this->drupalGet('admin/xs/snapshot-policy-types/add');
$this->verbose($this->drupalGetContent());
$this->assertResponse(403);

foreach ($this->policyTypes as $i => $type) {
$this->drupalGet('admin/structure/xs/snapshot-policy-types/' . $type->type . '/delete');
$this->drupalGet('admin/xs/snapshot-policy-types/' . $type->type . '/delete');
$this->verbose($this->drupalGetContent());
$this->assertResponse(403);

$this->drupalGet('admin/structure/xs/snapshot-policy-types/' . $type->type . '/edit');
$this->drupalGet('admin/xs/snapshot-policy-types/' . $type->type . '/edit');
$this->verbose($this->drupalGetContent());
$this->assertResponse(403);

$this->drupalGet('admin/structure/xs/snapshot-policy-types/' . $type->type . '/clone');
$this->drupalGet('admin/xs/snapshot-policy-types/' . $type->type . '/clone');
$this->verbose($this->drupalGetContent());
$this->assertResponse(403);
}
Expand Down
8 changes: 4 additions & 4 deletions modules/xs_snapshot_policy/xs_snapshot_policy.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ function xs_snapshot_policy_type_form_submit(&$form, &$form_state) {
xs_snapshot_policy_type_save($snapshot_policy_type);

// Redirect user back to list of snapshot-policy types.
$form_state['redirect'] = 'admin/structure/xs/snapshot-policy-types';
$form_state['redirect'] = 'admin/xs/snapshot-policy-types';
}

/**
* Deletes snapshot policy.
*/
function xs_snapshot_policy_type_form_submit_delete(&$form, &$form_state) {
$form_state['redirect'] = 'admin/structure/xs/snapshot-policy-types/' . $form_state['xs_snapshot_policy_type']->type . '/delete';
$form_state['redirect'] = 'admin/xs/snapshot-policy-types/' . $form_state['xs_snapshot_policy_type']->type . '/delete';
}

/**
Expand All @@ -107,7 +107,7 @@ function xs_snapshot_policy_type_form_delete_confirm($form, &$form_state, $snaps
* Snapshot Policy type delete form validate handler.
*/
function xs_snapshot_policy_type_form_delete_confirm_validate($form, &$form_state) {

}

/**
Expand All @@ -126,5 +126,5 @@ function xs_snapshot_policy_type_form_delete_confirm_submit($form, &$form_state)
'%title' => $snapshot_policy_type->label,
)));

$form_state['redirect'] = 'admin/structure/xs/snapshot-policy-types';
$form_state['redirect'] = 'admin/xs/snapshot-policy-types';
}
10 changes: 5 additions & 5 deletions modules/xs_snapshot_policy/xs_snapshot_policy.module
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function xs_snapshot_policy_cron() {

// Check if the policy maximum snapshots could be satisfied.
// Load all automated snapshots for the VM.
$server_snapshots = $xs_vm->getSnapshots();
$server_snapshots = $xs_vm->getSnapshots(TRUE);
$automated_snapshots = xs_snapshot_policy_filter_automated_snapshots($server_snapshots);

// Count the number of snapshots for the VM.
Expand Down Expand Up @@ -663,7 +663,7 @@ function xs_snapshot_policy_entity_info() {
'module' => 'xs_snapshot_policy',
// Enable the entity API's admin UI.
'admin ui' => array(
'path' => 'admin/structure/xs/snapshot-policy-types',
'path' => 'admin/xs/snapshot-policy-types',
'file' => 'xs_snapshot_policy.admin.inc',
'controller class' => 'SnapshotPolicyTypeUIController',
),
Expand Down Expand Up @@ -695,8 +695,8 @@ function xs_snapshot_policy_entity_info_alter(&$entity_info) {
$entity_info['xs_snapshot_policy']['bundles'][$type] = array(
'label' => $info->label,
'admin' => array(
'path' => 'admin/structure/xs/snapshot-policy-types/manage/%xs_snapshot_policy_type',
'real path' => 'admin/structure/xs/snapshot-policy-types/manage/' . $type,
'path' => 'admin/xs/snapshot-policy-types/manage/%xs_snapshot_policy_type',
'real path' => 'admin/xs/snapshot-policy-types/manage/' . $type,
'bundle argument' => 4,
),
);
Expand All @@ -709,7 +709,7 @@ function xs_snapshot_policy_entity_info_alter(&$entity_info) {
function xs_snapshot_policy_menu() {
$items = array();

$items['admin/structure/xs/snapshot-policy-types/%xs_snapshot_policy_type/delete'] = array(
$items['admin/xs/snapshot-policy-types/%xs_snapshot_policy_type/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('xs_snapshot_policy_type_form_delete_confirm', 4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function xs_snapshot_policy_views_default_views() {

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'admin/structure/xs/snapshot-policy';
$handler->display->display_options['path'] = 'admin/xs/snapshot-policy';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Policies';
$handler->display->display_options['menu']['weight'] = '0';
Expand Down
4 changes: 2 additions & 2 deletions tests/xs.common.test
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ abstract class XenServerTestCase extends DrupalWebTestCase {
$edit[$i]['time'] = ($i + 1) * 3600;
$edit[$i]['type'] = ($i + 1) . '_hourly';

$this->drupalPost('admin/structure/xs/snapshot-policy-types/add', $edit[$i], 'Save');
$this->drupalPost('admin/xs/snapshot-policy-types/add', $edit[$i], 'Save');
$this->verbose($this->drupalGetContent());
$this->drupalGet('admin/structure/xs/snapshot-policy-types');
$this->drupalGet('admin/xs/snapshot-policy-types');
$this->assertResponse(200);
$this->assertText($edit[$i]['label']);
$this->assertLink('edit', $i);
Expand Down
71 changes: 71 additions & 0 deletions xs.module
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ function xs_permission() {
function xs_menu() {
$items = array();

$items['admin/xs'] = array(
'title' => 'XenServer',
'access arguments' => array('access administration pages'),
'page callback' => '_xs_system_admin_menu_block_page',
'weight' => 9,
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'management',
);

$items['node/%node/xs-actions/%'] = array(
'title' => t('Confirm action'),
'description' => 'Use to reboot the VPS gracefully',
Expand Down Expand Up @@ -143,6 +152,68 @@ function xs_menu() {
return $items;
}

/**
* Menu callback for admin page admin/xs.
*/
function _xs_system_admin_menu_block_page() {
$item = menu_get_item('admin/xs/action-log');
$content = _xs_system_admin_menu_block($item);

return theme('admin_block_content', array('content' => $content));
}

/**
* Provide a single block on the administration overview page.
*/
function _xs_system_admin_menu_block($item) {
$cache = &drupal_static(__FUNCTION__ . $item['path'], array());
// If we are calling this function for a menu item that corresponds to a
// local task (for example, admin/tasks), then we want to retrieve the
// parent item's child links, not this item's (since this item won't have
// any).
if ($item['tab_root'] != $item['path']) {
$item = menu_get_item($item['tab_root_href']);
}

if (!isset($item['mlid'])) {
$item += db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'", array(':path' => $item['path']))->fetchAssoc();
}

if (isset($cache[$item['mlid']])) {
return $cache[$item['mlid']];
}

$content = array();
$query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
$query->join('menu_router', 'm', 'm.path = ml.router_path');
$query
->fields('ml')
// Weight should be taken from {menu_links}, not {menu_router}.
->fields('m', array_diff(drupal_schema_fields_sql('menu_router'), array('weight')))
->condition('ml.plid', $item['mlid'])
->condition('ml.menu_name', $item['menu_name'])
->condition('ml.hidden', 0);

foreach ($query->execute() as $link) {
_menu_link_translate($link);
if ($link['access']) {
// The link description, either derived from 'description' in
// hook_menu() or customized via menu module is used as title attribute.
if (!empty($link['localized_options']['attributes']['title'])) {
$link['description'] = $link['localized_options']['attributes']['title'];
unset($link['localized_options']['attributes']['title']);
}
// Prepare for sorting as in function _menu_tree_check_access().
// The weight is offset so it is always positive, with a uniform 5-digits.
$key = (50000 + $link['weight']) . ' ' . drupal_strtolower($link['title']) . ' ' . $link['mlid'];
$content[$key] = $link;
}
}
ksort($content);
$cache[$item['mlid']] = $content;
return $content;
}

/**
* Callback for user-vms URL.
*
Expand Down
4 changes: 2 additions & 2 deletions xs.views_default.inc
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ function xs_views_default_views() {
3 => 0,
4 => 0,
);
$handler->display->display_options['path'] = 'admin/structure/xs/action-log';
$handler->display->display_options['path'] = 'admin/xs/action-log';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Action Log';
$handler->display->display_options['menu']['weight'] = '0';
Expand Down Expand Up @@ -902,7 +902,7 @@ function xs_views_default_views() {
$handler->display->display_options['fields']['created']['date_format'] = 'today time ago';
$handler->display->display_options['fields']['created']['second_date_format'] = 'medium';
$handler->display->display_options['defaults']['arguments'] = FALSE;
$handler->display->display_options['path'] = 'admin/structure/xs/policy-log';
$handler->display->display_options['path'] = 'admin/xs/policy-log';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Policies log';
$handler->display->display_options['menu']['weight'] = '0';
Expand Down

0 comments on commit 905df39

Please sign in to comment.