} $meta_data = $dropbuddy->get_meta_data($destination['directory']); /* echo '<pre>'; print_r( $meta_data ) ); echo '</pre>'; */ // Delete dropbox backups if (!empty($_POST['delete_file'])) { $delete_count = 0; if (!empty($_POST['files']) && is_array($_POST['files'])) { // loop through and delete dropbox files foreach ($_POST['files'] as $dropboxfile) { $delete_count++; // Delete dropbox file $dropbuddy->delete($dropboxfile); } } if ($delete_count > 0) { $this->alert('Deleted ' . $delete_count . ' file(s).'); $meta_data = $dropbuddy->get_meta_data($destination['directory']); // Refresh listing. } } // Copy dropbox backups to the local backup files if (!empty($_GET['copy_file'])) { $this->alert('The remote file is now being copied to your <a href="' . $this->_selfLink . '-backup">local backups</a>.'); $this->log('Scheduling Cron for creating Dropbox copy.'); wp_schedule_single_event(time(), $this->_parent->_var . '-cron_dropbox_copy', array($_GET['destination_id'], $_GET['copy_file'])); spawn_cron(time() + 150); // Adds > 60 seconds to get around once per minute cron running limit.
function remote_send_dropbox($token, $directory, $file, $limit = 0) { $this->log('Starting Dropbox transfer.'); require_once $this->_pluginPath . '/lib/dropbuddy/dropbuddy.php'; $dropbuddy = new pluginbuddy_dropbuddy($this, $token); if ($dropbuddy->authenticate() !== true) { $this->log('Dropbox authentication failed in remote_send_dropbox.'); return false; } $this->log('About to put object (the file) to Dropbox cron.'); $status = $dropbuddy->put_file($directory . '/' . basename($file), $file); //if ( $status['httpStatus'] != 200 ) { if ($status === true) { $this->log('SUCCESS sending to Dropbox!'); } else { $this->log('Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error'); return false; } // Start remote backup limit if ($limit > 0) { $this->log('Dropbox file limit in place. Proceeding with enforcement.'); $meta_data = $dropbuddy->get_meta_data($directory); // Create array of backups and organize by date $bkupprefix = $this->backup_prefix(); $backups = array(); foreach ((array) $meta_data['contents'] as $file) { // check if file is backup if (strpos($file['path'], 'backup-' . $bkupprefix . '-') !== FALSE) { $backups[$file['path']] = strtotime($file['modified']); } } arsort($backups); if (count($backups) > $limit) { $this->log('Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.'); $i = 0; $delete_fail_count = 0; foreach ($backups as $buname => $butime) { $i++; if ($i > $limit) { if (!$dropbuddy->delete($buname)) { // Try to delete backup on Dropbox. Increment failure count if unable to. $this->log('Unable to delete excess Dropbox file: `' . $buname . '`'); $delete_fail_count++; } } } if ($delete_fail_count !== 0) { $this->mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count)); } } } else { $this->log('No Dropbox file limit to enforce.'); } // End remote backup limit return true; }