function put($options = array()) { $result = FALSE; $url = empty($options['url']) ? '' : $options['url']; $path = empty($options['path']) ? '' : $options['path']; if (!($url && $path)) { throw new InvalidArgumentException('Send array with url and path keys as first argument'); } $ignore = empty($options['ignore']) ? array() : $options['ignore']; $is_folder = is_dir($url); $urls = array(); if ($is_folder) { $path = end_with_slash($path); $urls = MovieMasher_File::files($url); } else { $urls[] = $url; } $z = sizeof($urls); //if ($this->getOption('Verbose')) $this->log(__METHOD__ . ' putting ' . $z . ' file' . (($z == 1) ? '' : 's') . ': ' . join("\n", $urls)); $errors = 0; // TODO: these could be config options $max_errors = 3; $wait_seconds = 30; for ($i = 0; $i < $z; $i++) { $options['url'] = $urls[$i]; if (in_array($options['url'], $ignore)) { continue; } if ($is_folder) { $options['path'] = $path . substr($options['url'], strlen(end_with_slash($url))); } try { $this->_put($options); $errors = 0; // one success resets error and result $result = TRUE; } catch (Exception $ex) { $result = FALSE; $errors++; if ($errors > $max_errors) { throw $ex; } $i--; $this->log(__METHOD__ . ' waiting ' . $wait_seconds . ' seconds after error ' . $errors . ': ' . $ex->getMessage()); sleep($wait_seconds); } } return $result; }
function MovieMasher_File_HTTP($config = array()) { parent::MovieMasher_File($config); }
function MovieMasher_File_System($config = array()) { parent::MovieMasher_File($config); }
function _populateDefaults() { parent::_populateDefaults(); $this->_configDefaults['AWSAccessKeyID'] = array('value' => 'STRING', 'description' => "AWS Access Key ID", 'default' => ''); $this->_configDefaults['AWSSecretAccessKey'] = array('value' => 'STRING', 'description' => "AWS Secrect Access Key", 'default' => ''); }