install-network.php 5.03 KB
Newer Older
imac's avatar
imac committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
<?php 

// vars
$button = __('Upgrade Sites');


// extract
extract($args);

?>
<div id="acf-upgrade-wrap" class="wrap">
	
	<h1><?php _e("Advanced Custom Fields Database Upgrade",'acf'); ?></h1>
	
	<p><?php echo sprintf( __("The following sites require a DB upgrade. Check the ones you want to update and then click %s.", 'acf'), '"' . $button . '"'); ?></p>
	
	<p><input type="submit" name="upgrade" value="<?php echo $button; ?>" class="button" id="upgrade-sites"></p>
	
	<table class="wp-list-table widefat">
		
		<thead>
			<tr>
				<td class="manage-column check-column" scope="col"><input type="checkbox" id="sites-select-all"></td>
				<th class="manage-column" scope="col" style="width:33%;"><label for="sites-select-all"><?php _e("Site", 'acf'); ?></label></th>
				<th><?php _e("Description", 'acf'); ?></th>
			</tr>
		</thead>
	
		<tfoot>
		<tr>
			<td class="manage-column check-column" scope="col"><input type="checkbox" id="sites-select-all-2"></td>
			<th class="manage-column" scope="col"><label for="sites-select-all-2"><?php _e("Site", 'acf'); ?></label></th>
			<th><?php _e("Description", 'acf'); ?></th>
		</tr>
		</tfoot>
		
		<tbody id="the-list">
		
		<?php foreach( $sites as $i => $site ): ?>
			
			<tr<?php if( $i % 2 == 0 ): ?> class="alternate"<?php endif; ?>>
				<th class="check-column" scope="row">
				<?php if( $site['updates'] ): ?>
					<input type="checkbox" value="<?php echo $site['blog_id']; ?>" name="checked[]">
				<?php endif; ?>
				</th>
				<td>
					<strong><?php echo $site['name']; ?></strong><br /><?php echo $site['url']; ?>
				</td>
				<td>
				<?php if( $site['updates'] ): ?>
					<span class="response"><?php printf(__('Site requires database upgrade from %s to %s', 'acf'), $site['acf_version'], $plugin_version); ?></span>
				<?php else: ?>
					<?php _e("Site is up to date", 'acf'); ?>
				<?php endif; ?>
				</td>
			</tr>
			
		<?php endforeach; ?>
		
		</tbody>
		
	</table>
	
	<p><input type="submit" name="upgrade" value="<?php echo $button; ?>" class="button" id="upgrade-sites-2"></p>
	
	<p class="show-on-complete"><?php echo sprintf( __('Database Upgrade complete. <a href="%s">Return to network dashboard</a>', 'acf'), network_admin_url() ); ?></p>
	
	<style type="text/css">
		
		/* hide show */
		.show-on-complete {
			display: none;
		}
		
	</style>
	
	<script type="text/javascript">
	(function($) {
		
		var upgrader = {
			
			$buttons: null,
			
			$inputs: null,
			i: 0,
			
			init : function(){
				
				// reference
				var self = this;
				
				
				// vars
				this.$buttons = $('#upgrade-sites, #upgrade-sites-2');
				
				
				// events
				this.$buttons.on('click', function( e ){
					
					// prevent default
					e.preventDefault();
					
					
					// confirm
					var answer = confirm("<?php _e('It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'acf'); ?>");
					
					
					// bail early if no confirm
					if( !answer ) {
						
						return;
						
					}
					
					
					// populate inputs
					self.$inputs = $('#the-list input:checked');
					
					
					// upgrade
					self.upgrade();
					
				});
				
				
				// return
				return this;
				
			},
			
			upgrade: function(){
				
				// reference
				var self = this;
				
				
				// bail early if no sites
				if( !this.$inputs.length ) {
					
					return;
					
				}
				
				
				// complete
				if( this.i >= this.$inputs.length ) {
					
					this.complete();
					return;
					
				}
				
				
				// disable buttons
				this.$buttons.attr('disabled', 'disabled');
				
				
				// vars
				var $input = this.$inputs.eq( this.i ),
					$tr = $input.closest('tr'),
					text = '<?php _e('Upgrade complete', 'acf'); ?>';
				
				
				// add loading
				$tr.find('.response').html('<i class="acf-loading"></i></span> <?php printf(__('Upgrading data to version %s', 'acf'), $plugin_version); ?>');
				
				
				// get results
			    var xhr = $.ajax({
			    	url:		'<?php echo admin_url('admin-ajax.php'); ?>',
					dataType:	'json',
					type:		'post',
					data:		{
						action:		'acf/admin/db_update',
						nonce:		'<?php echo wp_create_nonce('acf_db_update'); ?>',
						blog_id:	$input.val(),
					},
					success: function( json ){
						
						// remove input
						$input.prop('checked', false);
						$input.remove();
						
						
						// vars
						var message = acf.get_ajax_message(json);
						
						
						// bail early if no message text
						if( !message.text ) {
							
							return;
							
						}
						
						
						// update text
						text = '<pre>' + message.text +  '</pre>';
												
					},
					complete: function(){
						
						$tr.find('.response').html( text );
						
						
						// upgrade next site
						self.next();
						
					}
				});
				
			},
			
			next: function(){
				
				this.i++;
						
				this.upgrade();
				
			},
			
			complete: function(){
				
				// enable buttons
				this.$buttons.removeAttr('disabled');
				
				
				// show message
				$('.show-on-complete').show();
				
			}
			
		}.init();
		
	})(jQuery);	
	</script>
	
</div>