13 var spinner =
require(
'elgg/spinner');
14 var popup =
require(
'elgg/popup');
16 var UNKNOWN_COUNT = -1;
17 var upgrades = $(
'.elgg-item-object-elgg_upgrade');
26 var errorMessages = [];
36 var FAKE_TOTAL = 1000000;
47 if ($(
'.elgg-item-object-elgg_upgrade').length) {
48 $(
'#elgg-upgrades-run').removeClass(
'hidden').click(
run);
51 $(document).
on(
'click',
'.elgg-menu-item-run-upgrade > a', runSingle);
53 upgrades.each(
function(key,
value) {
55 $(
value).find(
'.elgg-progressbar').progressbar();
68 $(
'#elgg-upgrades-run').addClass(
'hidden');
71 upgrade = upgrades.first();
82 function runSingle(e) {
83 var guid = $(
this).data().guid;
85 if (!$(
'#elgg-object-' + guid).length) {
90 upgrade = $(
'#elgg-object-' + guid);
102 function runUpgrade(advanceToNextWhenDone) {
104 if (typeof advanceToNextWhenDone !==
'boolean') {
106 advanceToNextWhenDone =
true;
109 upgrade = $(upgrade);
110 progressbar = upgrade.find(
'.elgg-progressbar');
111 counter = upgrade.find(
'.upgrade-counter');
112 percent = upgrade.find(
'.upgrade-percent');
113 timer = upgrade.find(
'.upgrade-timer');
114 messageList = upgrade.find(
'.upgrade-messages');
115 errorCounter = upgrade.find(
'.upgrade-error-counter');
116 data = upgrade.find(
'.upgrade-data');
119 total = data.attr(
'data-total');
122 guid = upgrade.attr(
'id').replace(
'elgg-object-',
'');
125 $(upgrade).find(
'.elgg-progressbar').progressbar({
127 max: (total == UNKNOWN_COUNT) ? FAKE_TOTAL : total
130 upgradeStartTime =
new Date().getTime();
133 processBatch(advanceToNextWhenDone);
141 function processBatch(advanceToNextWhenDone) {
143 if (typeof advanceToNextWhenDone !==
'boolean') {
145 advanceToNextWhenDone =
true;
153 options.data = elgg.security.addToken(options.data);
155 options.success =
function(json) {
157 if (json.system_messages.error.length) {
159 $(json.system_messages.error).each(
function(key,
message) {
160 if ($.inArray(
message, errorMessages) === -1) {
161 var msg =
'<li>' +
message +
'</li>';
162 messageList.append(msg);
168 $(json.output.errors).each(
function(key,
message) {
169 var msg =
'<li>' +
message +
'</li>';
170 messageList.append(msg);
174 numSuccess = parseInt(json.output.numSuccess);
175 numError = parseInt(json.output.numErrors);
177 numProcessed += (numSuccess + numError);
180 if (total == UNKNOWN_COUNT) {
181 counter.text(numProcessed +
'/???');
183 counter.text(numProcessed +
'/' + total);
187 if (total == UNKNOWN_COUNT) {
188 fakeDone = Math.round(FAKE_TOTAL - (FAKE_TOTAL - fakeDone) / 2);
189 progressbar.progressbar({
value: fakeDone});
191 percentage = parseInt(numProcessed * 100 / total);
192 progressbar.progressbar({
value: numProcessed});
197 .text(elgg.echo(
'upgrade:error_count', [messages.length]))
198 .css(
'color',
'red');
204 if (total == UNKNOWN_COUNT) {
205 done = json.output.isComplete;
207 done = numProcessed >= total;
213 elgg.register_error(elgg.echo(
'upgrade:finished_with_errors'));
216 if (total == UNKNOWN_COUNT) {
217 counter.text(numProcessed +
'/' + numProcessed);
218 progressbar.progressbar({
value: FAKE_TOTAL});
222 percent.html(
'100%');
225 numSuccess = numError = numProcessed = percentage = 0;
228 if (advanceToNextWhenDone) {
230 upgrade = upgrade.next();
235 if (upgrade.length) {
237 runUpgrade(advanceToNextWhenDone);
240 $(
'#upgrade-finished').removeClass(
'hidden');
247 if (total != UNKNOWN_COUNT) {
248 percentage = parseInt(numProcessed * 100 / total);
250 percent.html(percentage +
'%');
254 processBatch(advanceToNextWhenDone);
259 return elgg.post(
'action/admin/upgrade', options);
265 function updateCounter() {
266 var now =
new Date().getTime();
269 var difference = (now - upgradeStartTime) / 1000;
272 var unProcessed = total - numProcessed;
274 var timeLeft = Math.round((difference / numProcessed) * unProcessed);
279 var seconds = timeLeft;
281 if (timeLeft < 3600) {
282 var minutes = Math.floor(timeLeft / 60);
283 var seconds = timeLeft % 60;
286 var hours = Math.floor(timeLeft / 3600);
287 var timeLeft = timeLeft % 3600;
288 var minutes = Math.floor(timeLeft / 60);
289 var seconds = timeLeft % 60;
293 hours = formatDigits(hours);
294 minutes = formatDigits(minutes);
295 seconds = formatDigits(seconds);
297 var
value = hours +
':' + minutes +
':' + seconds;
308 function formatDigits(time) {
309 time = Math.floor(time);
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when run
elgg require
Throw an error if the required package isn't present.
define(function(require){var $=require('jquery');var elgg=require('elgg');var spinner=require('elgg/spinner');var popup=require('elgg/popup');var UNKNOWN_COUNT=-1;var upgrades=$('.elgg-item-object-elgg_upgrade');var upgrade;var guid;var progressbar;var upgradeStartTime;var timer;var counter;var percent;var errorCounter;var errorMessages=[];var numSuccess;var numError;var numProcessed=0;var total;var messages=[];var messageList;var percentage=0;var FAKE_TOTAL=1000000;var fakeDone=0;function init(){if($('.elgg-item-object-elgg_upgrade').length){$('#elgg-upgrades-run').removeClass('hidden').click(run);}$(document).on('click', '.elgg-menu-item-run-upgrade > a', runSingle);upgrades.each(function(key, value){$(value).find('.elgg-progressbar').progressbar();});}function run(e){e.preventDefault();$('#elgg-upgrades-run').addClass('hidden');spinner.start();upgrade=upgrades.first();runUpgrade();return false;}function runSingle(e){var guid=$(this).data().guid;if(!$('#elgg-object-'+guid).length){return;}spinner.start();upgrade=$('#elgg-object-'+guid);runUpgrade(false);popup.close();}function runUpgrade(advanceToNextWhenDone){if(typeof advanceToNextWhenDone!== 'boolean'){advanceToNextWhenDone=true;}upgrade=$(upgrade);progressbar=upgrade.find('.elgg-progressbar');counter=upgrade.find('.upgrade-counter');percent=upgrade.find('.upgrade-percent');timer=upgrade.find('.upgrade-timer');messageList=upgrade.find('.upgrade-messages');errorCounter=upgrade.find('.upgrade-error-counter');data=upgrade.find('.upgrade-data');total=data.attr('data-total');guid=upgrade.attr('id').replace('elgg-object-', '');$(upgrade).find('.elgg-progressbar').progressbar({value:0, max:(total==UNKNOWN_COUNT)?FAKE_TOTAL:total});upgradeStartTime=new Date().getTime();percentage=0;processBatch(advanceToNextWhenDone);}function processBatch(advanceToNextWhenDone){if(typeof advanceToNextWhenDone!== 'boolean'){advanceToNextWhenDone=true;}var options={data:{guid:guid}, dataType: 'json'};options.data=elgg.security.addToken(options.data);options.success=function(json){if(json.system_messages.error.length){$(json.system_messages.error).each(function(key, message){if($.inArray(message, errorMessages)===-1){var msg= '< li >'+message+ '</li >';messageList.append(msg);messages.push(message);}});}$(json.output.errors).each(function(key, message){var msg= '< li >'+message+ '</li >';messageList.append(msg);messages.push(message);});numSuccess=parseInt(json.output.numSuccess);numError=parseInt(json.output.numErrors);numProcessed+=(numSuccess+numError);if(total==UNKNOWN_COUNT){counter.text(numProcessed+ '/?^);}else{counter.text(numProcessed+ '/'+total);}if(total==UNKNOWN_COUNT){fakeDone=Math.round(FAKE_TOTAL-(FAKE_TOTAL-fakeDone)/2);progressbar.progressbar({value:fakeDone});}else{percentage=parseInt(numProcessed *100/total);progressbar.progressbar({value:numProcessed});}if(numError > 0){errorCounter.text(elgg.echo('upgrade:error_count', [messages.length])).css('color', 'red');}updateCounter();var done;if(total==UNKNOWN_COUNT){done=json.output.isComplete;}else{done=numProcessed >=total;}if(done){if(numError > 0){elgg.register_error(elgg.echo('upgrade:finished_with_errors'));}if(total==UNKNOWN_COUNT){counter.text(numProcessed+ '/'+numProcessed);progressbar.progressbar({value:FAKE_TOTAL});}percent.html('100%');numSuccess=numError=numProcessed=percentage=0;messages=[];if(advanceToNextWhenDone){upgrade=upgrade.next();}else{upgrade= '';}if(upgrade.length){runUpgrade(advanceToNextWhenDone);}else{spinner.stop();$('#upgrade-finished').removeClass('hidden');}return;}if(total!=UNKNOWN_COUNT){percentage=parseInt(numProcessed *100/total);percent.html(percentage+ '%');}processBatch(advanceToNextWhenDone);};return elgg.post('action/admin/upgrade', options);}function updateCounter(){var now=new Date().getTime();var difference=(now-upgradeStartTime)/1000;var unProcessed=total-numProcessed;var timeLeft=Math.round((difference/numProcessed)*unProcessed);if(timeLeft< 60){var hours= '00';var minutes= '00';var seconds=timeLeft;}else{if(timeLeft< 3600){var minutes=Math.floor(timeLeft/60);var seconds=timeLeft%60;var hours= '00';}else{var hours=Math.floor(timeLeft/3600);var timeLeft=timeLeft%3600;var minutes=Math.floor(timeLeft/60);var seconds=timeLeft%60;}}hours=formatDigits(hours);minutes=formatDigits(minutes);seconds=formatDigits(seconds);var value=hours+ ':'+minutes+ ':'+seconds;timer.html(value);}function formatDigits(time){time=Math.floor(time);if(time< 1){return '00';}if(time< 10){return '0'+time;}return time;}init();})
Javascript that takes care of running batch upgrades.
Bundled plugins(the contents of the"/mod"directory) are available only under the GPLv2 license.The remainder of the project is available under either MIT or GPLv2.Both licenses can be found below.More info and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on