function remote_send_dropbox($token, $directory, $file) { $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('Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error'); return false; } $this->log('SUCCESS sending to Dropbox!'); return true; }
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; }