function column_status($item) {

			$status = array();
			$status['archives'] = array();
			$status['archives']['pending'] = 0;
			$status['archives']['fail'] = 0;
			$status['archives']['complete'] = 0;

			$status['destination']['pending'] = 0;
			$status['destination']['fail'] = 0;
			$status['destination']['complete'] = 0;

			if ((!isset($item['data'])) || (!count($item['data']))) {
				$status['archives']['pending'] += 1;
			} else {
				ksort($item['data']);
				foreach($item['data'] as $data_item) {

					if (!isset($data_item['archive-status'])) {
						$status['archives']['pending'] += 1;
					} else {
						$status_item = snapshot_utility_latest_data_item($data_item['archive-status']);
						if (!$status_item) {
							$status['archives']['pending'] += 1;

						} else if (isset($status_item['errorStatus'])) {
							if ($status_item['errorStatus'] === true)
								$status['archives']['fail'] += 1;
							else if ($status_item['errorStatus'] !== true)
								$status['archives']['complete'] += 1;
						}
					}

					if ((!isset($data_item['destination'])) || ($data_item['destination'] != $item['destination'])) {
						$data_item['destination'] = $item['destination'];
					}
					//echo "data_item[destination-status]<pre>"; print_r($)
					if ((isset($data_item['destination'])) && ($data_item['destination'] != "local") && (!empty($data_item['destination']))) {
						if (!isset($data_item['destination-status'])) {
							$status['destination']['pending'] += 1;
						} else {
							$status_item = snapshot_utility_latest_data_item($data_item['destination-status']);
							//echo "status_item<pre>"; print_r($status_item); echo "</pre>";
							if (!$status_item) {
								$status['destination']['pending'] += 1;
							} else if ((isset($status_item['sendFileStatus'])) && ($status_item['sendFileStatus'] === true)) {
								$status['destination']['complete'] += 1;
							} else if ($status_item['errorStatus'] === true) {
								$status['destination']['fail'] += 1;
							}
						}
					}
				}
			}

			//echo "status<pre>"; print_r($status); echo "</pre>";

			$status_output = '';
			foreach($status['archives'] as $_key => $_count) {
				if ($_count == 0) continue;

				switch($_key) {
					case 'pending':
						if (strlen($status_output)) $status_output .= ', ';
						$status_output .= $_count ." ". __('Pending', SNAPSHOT_I18N_DOMAIN);
						break;

					case 'fail':
						if (strlen($status_output)) $status_output .= ', ';
						$status_output .= $_count ." ". __('Fail', SNAPSHOT_I18N_DOMAIN);
						break;

					case 'complete':
						if (strlen($status_output)) $status_output .= ', ';
						$status_output .= $_count ." ". __('Complete', SNAPSHOT_I18N_DOMAIN);
						break;
				}
			}

			//if (strlen($status_output))
			//	echo __('Archives:', SNAPSHOT_I18N_DOMAIN) ." ".$status_output ."<br />";
			//else
			//	echo __('Archives:', SNAPSHOT_I18N_DOMAIN) ." ".$status_output ."<br />";
			//echo "status_output=[". $status_output ."]<br />";


			$status_output = '';
			foreach($status['destination'] as $_key => $_count) {
				if ($_count == 0) continue;

				switch($_key) {
					case 'pending':
						if (strlen($status_output)) $status_output .= ', ';
						$status_output .= $_count ." ". __('Pending', SNAPSHOT_I18N_DOMAIN);
						break;

					case 'fail':
						if (strlen($status_output)) $status_output .= ', ';
						$status_output .= $_count ." ". __('Fail', SNAPSHOT_I18N_DOMAIN);
						break;

					case 'complete':
						if (strlen($status_output)) $status_output .= ', ';
						$status_output .= $_count ." ". __('Complete', SNAPSHOT_I18N_DOMAIN);
						break;
				}
			}

			if (strlen($status_output))
				echo "<br />". __('Destination:', SNAPSHOT_I18N_DOMAIN) ." ".$status_output ."<br />";
			//else
			//	echo __('Archives:', SNAPSHOT_I18N_DOMAIN) ." ".$status_output ."<br />";
			//echo "status_output=[". $status_output ."]<br />";
		}
Example #2
0
 function process_item_send_archive($item, $data_item, $snapshot_locker)
 {
     $item_key = $item['timestamp'];
     $data_item_key = $data_item['timestamp'];
     // Create a logged for each item/data_item combination because that is how the log files are setup
     if (isset($snapshot_logger)) {
         unset($snapshot_logger);
     }
     $snapshot_logger = new SnapshotLogger($this->_settings['backupLogFolderFull'], $item_key, $data_item_key);
     // If the file has already been transmitted the move to the next one.
     if (isset($data_item['destination-status']) && count($data_item['destination-status'])) {
         $destination_status = snapshot_utility_latest_data_item($data_item['destination-status']);
         //$snapshot_logger->log_message("destination_status<pre>: ". print_r($destination_status, true) ."</pre>");
         //echo "destination_status<pre>"; print_r($destination_status); echo "</pre>";
         //die();
         // If we have a positive 'sendFileStatus' continue on
         if (isset($destination_status['sendFileStatus']) && $destination_status['sendFileStatus'] == true) {
             //echo "finished item[". $item_key ."] data_item_key[". $data_item_key ."] file[". $data_item['filename'] ."]<br />";
             return;
         }
         /*
         				else if ( (isset($destination_status['responseArray'])) && (count($destination_status['responseArray']))
         					     && (isset($destination_status['errorStatus'])) && ($destination_status['errorStatus'] != true) ) {
         					return;
         				} */
     }
     //echo "DEBUG: processing item[". $item_key ."] data_item[". $data_item_key ."] file[". $data_item['filename'] ."]<br />";
     //return
     // Get the archive folder
     $current_backupFolder = $this->snapshot_get_item_destination_path($item, $data_item);
     if (empty($current_backupFolder)) {
         $current_backupFolder = $this->snapshot_get_setting('backupBaseFolderFull');
     }
     //echo "DEBUG: current_backupFolder=[". $current_backupFolder ."]<br />";
     // If the data_item destination is not empty...
     if (isset($data_item['destination']) && !empty($data_item['destination'])) {
         // We make sure to check it against the item master. If they don't match it means
         // the data_item archive was sent to the data_item destination. We probably don't
         // have the archive file to resent.
         //				echo "destination data_item[". $data_item['destination']."] item[". $item['destination'] ."]<br />";
         //				if ($data_item['destination'] !== $item['destination']) {
         //					return;
         //				}
     }
     $destination_key = $item['destination'];
     if (!isset($this->config_data['destinations'][$destination_key])) {
         return;
     }
     $destination = $this->config_data['destinations'][$destination_key];
     if (!isset($destination['type'])) {
         return;
     }
     if (!isset($this->_settings['destinationClasses'][$destination['type']])) {
         return;
     }
     $destination_object = $this->_settings['destinationClasses'][$destination['type']];
     $new_backupFolder = $this->snapshot_get_item_destination_path($item);
     if ($new_backupFolder && strlen($new_backupFolder)) {
         $destination['directory'] = $new_backupFolder;
     }
     if (!isset($data_item['destination-sync'])) {
         $data_item['destination-sync'] = "archive";
     }
     $files_sync = array();
     if ($data_item['destination-sync'] == "archive") {
         // If the data item is there but no final archive filename (probably stopped in an error). Abort
         if (!isset($data_item['filename']) || empty($data_item['filename'])) {
             return;
         }
         // See if we still have the archive file.
         // First check where we originally placed it.
         $backupFile = trailingslashit($current_backupFolder) . $data_item['filename'];
         if (!file_exists($backupFile)) {
             // Then check is the detail Snapshot archive folder
             $current_backupFolder = $this->_settings['backupBaseFolderFull'];
             $backupFile = trailingslashit($current_backupFolder) . $data_item['filename'];
             if (!file_exists($backupFile)) {
                 return;
             }
         }
         $snapshot_logger->log_message("Sending Archive: " . basename($backupFile) . " " . snapshot_utility_size_format(filesize($backupFile)));
         $snapshot_logger->log_message("Destination: " . $destination['type'] . ": " . stripslashes($destination['name']));
         $locker_info = $snapshot_locker->get_locker_info();
         $locker_info['file_name'] = $backupFile;
         $locker_info['file_size'] = filesize($backupFile);
         $snapshot_locker->set_locker_info($locker_info);
         $destination_object->snapshot_logger = $snapshot_logger;
         $destination_object->snapshot_locker = $snapshot_locker;
         $error_array = $destination_object->sendfile_to_remote($destination, $backupFile);
         //echo "error_array<pre>"; print_r($error_array); echo "</pre>";
         //$snapshot_logger->log_message("DEBUG: error_array<pre>". print_r($error_array, true)."</pre>");
         if (isset($error_array['responseArray']) && count($error_array['responseArray'])) {
             foreach ($error_array['responseArray'] as $message) {
                 $snapshot_logger->log_message($message);
             }
         }
         if (isset($error_array['errorStatus']) && $error_array['errorStatus'] == true) {
             if (isset($error_array['errorArray']) && count($error_array['errorArray'])) {
                 foreach ($error_array['errorArray'] as $message) {
                     $snapshot_logger->log_message("ERROR: " . $message);
                 }
             }
         }
         if (!isset($data_item['destination-status'])) {
             $data_item['destination-status'] = array();
         }
         $data_item['destination-status'][time()] = $error_array;
         //echo "destination-status<pre>"; print_r($data_item['destination-status']); echo "</pre>";
         //die();
         krsort($data_item['destination-status']);
         if (count($data_item['destination-status']) > 5) {
             $data_item['destination-status'] = array_slice($data_item['destination-status'], 0, 5, true);
         }
         $data_item['destination'] = $item['destination'];
         $data_item['destination-directory'] = $item['destination-directory'];
         //				echo "data_item<pre>"; print_r($data_item); echo "</pre>";
         //				die();
     } else {
         // We create an option to store the list of files we are sending. This is better than adding to the config data
         // for snapshot. Less loading of the master array. The list of files is a reference we pass to the sender function
         // of the destination. As files are sent they are removed from the array and the option is updated. So if something
         // happens we don't start from the first of the list. Could probably use a local file...
         $snapshot_sync_files_option = 'wpmudev_snapshot_sync_files_' . $item_key;
         $snapshot_sync_files = get_option($snapshot_sync_files_option);
         if (!$snapshot_sync_files) {
             $snapshot_sync_files = array();
         }
         $last_sync_timestamp = time();
         //$snapshot_logger->log_message("DEBUG: going to snapshot_gather_item_files");
         //$snapshot_logger->log_message("DEBUG: data_item<pre>". print_r($data_item, true), "</pre>");
         if (!isset($data_item['blog-id'])) {
             $data_item['blog-id'] = $item['blog-id'];
         }
         $gather_files_sync = $this->snapshot_gather_item_files($data_item);
         foreach ($data_item['files-sections'] as $file_section) {
             if ($file_section == "config" || $file_section == "config") {
                 $file_section = "files";
             }
             if (isset($gather_files_sync['included'][$file_section])) {
                 if (!isset($snapshot_sync_files['last-sync'][$file_section])) {
                     $snapshot_sync_files['last-sync'][$file_section] = 0;
                 }
                 foreach ($gather_files_sync['included'][$file_section] as $_file_idx => $_file) {
                     if (filemtime($_file) < $snapshot_sync_files['last-sync'][$file_section]) {
                         unset($gather_files_sync['included'][$file_section][$_file_idx]);
                     }
                 }
                 if (!isset($snapshot_sync_files['included'][$file_section])) {
                     $snapshot_sync_files['included'][$file_section] = array();
                 }
                 if (count($gather_files_sync['included'][$file_section])) {
                     $snapshot_sync_files['included'][$file_section] = array_merge($snapshot_sync_files['included'][$file_section], $gather_files_sync['included'][$file_section]);
                     $snapshot_sync_files['included'][$file_section] = array_unique($snapshot_sync_files['included'][$file_section]);
                     $snapshot_sync_files['included'][$file_section] = array_values($snapshot_sync_files['included'][$file_section]);
                 }
                 $snapshot_sync_files['last-sync'][$file_section] = $last_sync_timestamp;
             }
         }
         $destination_object->snapshot_logger = $snapshot_logger;
         $destination_object->snapshot_locker = $snapshot_locker;
         update_option($snapshot_sync_files_option, $snapshot_sync_files);
         $error_array = $destination_object->syncfiles_to_remote($destination, $snapshot_sync_files, $snapshot_sync_files_option);
         if (isset($error_array['errorStatus']) && $error_array['errorStatus'] == true) {
             if (isset($error_array['errorArray']) && count($error_array['errorArray'])) {
                 foreach ($error_array['errorArray'] as $message) {
                     $snapshot_logger->log_message("ERROR: " . $message);
                 }
             }
         }
         if (!isset($data_item['destination-status'])) {
             $data_item['destination-status'] = array();
         }
         $data_item['destination-status'][time()] = $error_array;
         krsort($data_item['destination-status']);
         if (count($data_item['destination-status']) > 5) {
             $data_item['destination-status'] = array_slice($data_item['destination-status'], 0, 5);
         }
         $data_item['destination'] = $item['destination'];
         $data_item['destination-directory'] = $item['destination-directory'];
         // See if we still have the archive file.
         // First check where we originally placed it.
         if (strlen($data_item['filename'])) {
             $backupFile = trailingslashit($current_backupFolder) . $data_item['filename'];
             if (!file_exists($backupFile)) {
                 // Then check is the detail Snapshot archive folder
                 $current_backupFolder = $this->_settings['backupBaseFolderFull'];
                 $backupFile = trailingslashit($current_backupFolder) . $data_item['filename'];
                 if (!file_exists($backupFile)) {
                     return $data_item;
                 }
             }
             //echo "backupFile=[". $backupFile ."]<br />";
             $snapshot_logger->log_message("Sending Archive: " . basename($backupFile));
             $snapshot_logger->log_message("Destination: " . $destination['type'] . ": " . stripslashes($destination['name']));
             $error_array = $destination_object->sendfile_to_remote($destination, $backupFile);
             //$snapshot_logger->log_message("DEBUG: error_array<pre>". print_r($error_array, true)."</pre>");
             if (isset($error_array['responseArray']) && count($error_array['responseArray'])) {
                 foreach ($error_array['responseArray'] as $message) {
                     $snapshot_logger->log_message($message);
                 }
             }
             if (isset($error_array['errorStatus']) && $error_array['errorStatus'] == true) {
                 if (isset($error_array['errorArray']) && count($error_array['errorArray'])) {
                     foreach ($error_array['errorArray'] as $message) {
                         $snapshot_logger->log_message("ERROR: " . $message);
                     }
                 }
             }
             if (!isset($data_item['destination-status'])) {
                 $data_item['destination-status'] = array();
             }
             $data_item['destination-status'][time()] = $error_array;
             krsort($data_item['destination-status']);
             if (count($data_item['destination-status']) > 5) {
                 $data_item['destination-status'] = array_slice($data_item['destination-status'], 0, 5);
             }
             $data_item['destination'] = $item['destination'];
             $data_item['destination-directory'] = $item['destination-directory'];
         }
     }
     return $data_item;
 }