Elgg  Version 1.9
upgrades.js
Go to the documentation of this file.
1 
5 elgg.provide('elgg.upgrades');
6 
7 // The already displayed messages are saved here
8 elgg.upgrades.errorMessages = [];
9 
10 elgg.upgrades.init = function () {
11  $('#upgrade-run').click(elgg.upgrades.run);
12 };
13 
19 elgg.upgrades.run = function(e) {
20  e.preventDefault();
21 
22  // The total amount of items to be upgraded
23  var total = $('#upgrade-total').text();
24 
25  // Initialize progressbar
26  $('.elgg-progressbar').progressbar({
27  value: 0,
28  max: total
29  });
30 
31  // Replace button with spinner when upgrade starts
32  $('#upgrade-run').addClass('hidden');
33  $('#upgrade-spinner').removeClass('hidden');
34 
35  // Start upgrade from offset 0
36  elgg.upgrades.upgradeBatch(0);
37 };
38 
44 elgg.upgrades.upgradeBatch = function(offset) {
45  var options = {
46  data: {
47  offset: offset
48  },
49  dataType: 'json'
50  };
51 
52  options.data = elgg.security.addToken(options.data);
53 
54  var upgradeCount = $('#upgrade-count');
55  var action = $('#upgrade-run').attr('href');
56 
57  options.success = function(json) {
58  // Append possible errors after the progressbar
59  if (json.system_messages.error.length) {
60  // Display only the errors that haven't already been shown
61  $(json.system_messages.error).each(function(key, message) {
62  if (jQuery.inArray(message, elgg.upgrades.errorMessages) === -1) {
63  var msg = '<li class="elgg-message elgg-state-error">' + message + '</li>';
64  $('#upgrade-messages').append(msg);
65 
66  // Add this error to the displayed errors
67  elgg.upgrades.errorMessages.push(message);
68  }
69  });
70  }
71 
72  // Increase success statistics
73  var numSuccess = $('#upgrade-success-count');
74  var successCount = parseInt(numSuccess.text()) + json.output.numSuccess;
75  numSuccess.text(successCount);
76 
77  // Increase error statistics
78  var numErrors = $('#upgrade-error-count');
79  var errorCount = parseInt(numErrors.text()) + json.output.numErrors;
80  numErrors.text(errorCount);
81 
82  // Increase total amount of processed items
83  var numProcessed = successCount + errorCount;
84  upgradeCount.text(numProcessed);
85 
86  // Increase the progress bar
87  $('.elgg-progressbar').progressbar({ value: numProcessed });
88  var total = $('#upgrade-total').text();
89 
90  if (numProcessed < total) {
91  var percent = parseInt(numProcessed * 100 / total);
92 
97  elgg.upgrades.upgradeBatch(errorCount);
98  } else {
99  $('#upgrade-spinner').addClass('hidden');
100  percent = '100';
101 
102  if (errorCount > 0) {
103  // Upgrade finished with errors. Give instructions on how to proceed.
104  elgg.register_error(elgg.echo('upgrade:finished_with_errors'));
105  } else {
106  // Upgrade is finished. Make one more call to mark it complete.
107  elgg.action(action, {'upgrade_completed': 1});
108  elgg.system_message(elgg.echo('upgrade:finished'));
109  }
110  }
111 
112  // Increase percentage
113  $('#upgrade-counter').text(percent + '%');
114  };
115 
116  // We use post() instead of action() so we can catch error messages
117  // and display them manually underneath the upgrade view.
118  return elgg.post(action, options);
119 };
120 
121 elgg.register_hook_handler('init', 'system', elgg.upgrades.init);
elgg
Definition: install.js:23
elgg message
Definition: admin.php:231
elgg input text
Definition: admin.php:478
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})
elgg action
Definition: ajax.js:178