Elgg  Version 4.3
Functions
upgrader.js File Reference

Go to the source code of this file.

Functions

 define (['jquery', 'elgg/Ajax', 'elgg/spinner', 'elgg/popup', 'elgg/system_messages', 'elgg/i18n', 'jquery-ui/widgets/progressbar'], function($, Ajax, spinner, popup, system_messages, i18n){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 run(event){event.preventDefault();$('#elgg-upgrades-run').addClass('hidden');spinner.start();upgrade=upgrades.first();runUpgrade();return false;}function runSingle(){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}, error:function(result){if(result.system_messages.error.length){$(result.error).each(function(key, message){if($.inArray(message, errorMessages)===-1){var msg= '< li >'+message+ '</li >';messageList.append(msg);messages.push(message);}});}$(result.errors).each(function(key, message){var msg= '< li >'+message+ '</li >';messageList.append(msg);messages.push(message);});}, success:function(result){numSuccess=parseInt(result.numSuccess);numError=parseInt(result.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(i18n.echo('upgrade:error_count', [messages.length])).css('color', 'red');}updateCounter();var done;if(total==UNKNOWN_COUNT||result.isComplete){done=result.isComplete;}else{done=numProcessed >=total;}if(done){if(numError > 0){system_messages.error(i18n.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();}return;}if(total!=UNKNOWN_COUNT){percentage=parseInt(numProcessed *100/total);percent.html(percentage+ '%');}processBatch(advanceToNextWhenDone);}};var ajax=new Ajax(false);return ajax.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;}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();});})
 Javascript that takes care of running batch upgrades. More...
 

Function Documentation

define ( function($, Ajax, spinner, popup, system_messages, i18n){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 run(event){event.preventDefault();$('#elgg-upgrades-run').addClass('hidden');spinner.start();upgrade=upgrades.first();runUpgrade();return false;}function runSingle(){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}, error:function(result){if(result.system_messages.error.length){$(result.error).each(function(key, message){if($.inArray(message, errorMessages)===-1){var msg= '< li >'+message+ '</li >';messageList.append(msg);messages.push(message);}});}$(result.errors).each(function(key, message){var msg= '< li >'+message+ '</li >';messageList.append(msg);messages.push(message);});}, success:function(result){numSuccess=parseInt(result.numSuccess);numError=parseInt(result.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(i18n.echo('upgrade:error_count', [messages.length])).css('color', 'red');}updateCounter();var done;if(total==UNKNOWN_COUNT||result.isComplete){done=result.isComplete;}else{done=numProcessed >=total;}if(done){if(numError > 0){system_messages.error(i18n.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();}return;}if(total!=UNKNOWN_COUNT){percentage=parseInt(numProcessed *100/total);percent.html(percentage+ '%');}processBatch(advanceToNextWhenDone);}};var ajax=new Ajax(false);return ajax.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;}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();});}  )

Javascript that takes care of running batch upgrades.

Parameters
function($,Ajax,spinner,popup,system_messages,i18n){varUNKNOWN_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 run(event){event.preventDefault();$('elgg-upgrades-run').addClass('hidden');spinner.start();upgrade=upgrades.first();runUpgrade();return false;}function runSingle(){var guid=.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=;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-', '');.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}, error:function(result){if(result.system_messages.error.length){$(result.error).each(function(key, message){if($.inArray(message, errorMessages)===-1){var msg= '< li >'+message+ '';messageList.append(msg);messages.push(message);}});}$(result.errors).each(function(key, message){var msg= '< li >'+message+ '';messageList.append(msg);messages.push(message);});}, success:function(result){numSuccess=parseInt(result.numSuccess);numError=parseInt(result.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(i18n.echo('upgrade:error_count', [messages.length])).css('color', 'red');}updateCounter();var done;if(total==UNKNOWN_COUNT||result.isComplete){done=result.isComplete;}else{done=numProcessed >=total;}if(done){if(numError > 0){system_messages.error(i18n.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();}return;}if(total!=UNKNOWN_COUNT){percentage=parseInt(numProcessed *100/total);percent.html(percentage+ '');}processBatch(advanceToNextWhenDone);}};var ajax=new Ajax(false);return ajax.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;}if($('.elgg-item-object-elgg_upgrade').length){$('elgg-upgrades-run').removeClass('hidden').click(run);}.on('click', '.elgg-menu-item-run-upgrade > a', runSingle);upgrades.each(function(key, value){.find('.elgg-progressbar').progressbar();});} Runs all individual upgrades one at a time
{Object}event Event object

Run a single upgrade

Takes care of processing a single upgrade in multiple batches

Parameters
booladvanceToNextWhenDone when the upgrade is done shoul it continue to the next available

Takes care of upgrading a single batch of items

Parameters
booladvanceToNextWhenDone when the upgrade is done shoul it continue to the next available

Displays estimated amount of time needed for a single upgrade to finish

Rounds hours, minutes or seconds and adds a leading zero if necessary

Parameters
{String}time
Returns
{String} time