Drupal-Admin
view release on metacpan or search on metacpan
lib/Drupal/Admin/ModuleState.pm view on Meta::CPAN
next if $module->group eq 'Core - required';
# Put this in an eval block so it doesn't die() if a field doesn't exist in the current page
# This happens e.g. when throttling is disabled
# NOTE: using tick() instead of field() doesn't allow us to use the index field,
# but field() doesn't seem to work???
#eval{ $self->mech->field($module->name, $module->checked, $module->index); };
eval{ $self->mech->tick($module->name, $module->value, $module->checked); };
}
# Commit the changes
my $response = $self->mech->click_button('name' => 'op');
$self->_warn('Failed to submit page: ' . $response->status_line) unless $response->is_success;
# Test to see whether all changes have been committed; retry if they haven't
$self->mech->get($url);
$self->mech->form_id('system-modules');
$newstate = $self->_getstate;
$unsynced = $self->_unsynced($self->modules, $newstate);
}
# Warn with a list of any out-of-sync modules
if( $unsynced ){
$self->_warn(
join("\n",
"commit() failed for the following modules:\n",
@{$unsynced}
)
);
}
$self->modules($newstate);
$self->log_trace("Leaving commit()");
}
#################################################################
# Private Methods
#################################################################
#
# Return a ref to a plain array of modules of the current website state
#
sub _getstate {
my($self) = @_;
$self->log_trace("Entering _getstate()");
my $url = $self->baseurl . '?q=admin/build/modules';
# Get and parse the status page
$self->mech->get($url);
my @result;
# Get all the groups (fieldsets)
my @group_trees = $self->mech->look_down("_tag", "fieldset");
foreach my $group_tree (@group_trees) {
my $group = $group_tree->look_down("_tag", 'legend')->as_text
|| $self->_die("Failed to extract module group name");
# Get all the checkboxes for that group
my @chboxes = $group_tree->look_down("_tag", "input",
"type", "checkbox");
foreach my $chx (@chboxes) {
my $name = $chx->attr_get_i('name');
$name =~ /^(.*)\[/;
my $type = $1;
my $id = $chx->attr_get_i('id');
my $value = $chx->attr_get_i('value');
my $checked = defined($chx->attr_get_i('checked')) ? 1 : 0;
my $disabled = defined($chx->attr_get_i('disabled')) ? 1 : 0;
# This must be called before creating the entry
my $index = $self-> _module_name_index($name, \@result);
my $chobj = new Drupal::Admin::ModuleCheckbox(
name => $name,
type => $type,
id => $id,
value => $value,
checked => $checked,
disabled => $disabled,
index => $index,
group => $group
);
push( @result, $chobj );
}
}
$self->log_trace("Leaving _getstate()");
return(\@result);
}
#
# Since field names are not (necessarily) unique, return the index
# value of the given module name (for use with WWW::Mechanize).
# Indices start with 1. Second argument is ref to plain array of modules
# that we're to examine.
#
sub _module_name_index {
my($self, $name, $modules) = @_;
$self->log_trace("Entering _module_name_index()");
# Find the greatest current index for this module name
my $index = 0;
foreach my $module ( @{$modules} ){
$index = $module->index
if $module->name eq $name && $module->index > $index
}
$self->log_trace("Leaving _module_name_index()");
( run in 1.289 second using v1.01-cache-2.11-cpan-39bf76dae61 )