protected function _putFileContents($contents) { $s3 = new Kwf_Util_Aws_S3(); $r = $s3->create_object(Kwf_Config::getValue('aws.uploadsBucket'), $this->id, array('body' => $contents, 'length' => strlen($contents), 'contentType' => $this->mime_type)); if (!$r->isOk()) { throw new Kwf_Exception($r->body); } $this->_deleteCache(); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!file_exists($_SERVER['HOME'] . '/.aws/config')) { throw new \Exception("Can't get aws config, set up eb cli first"); } $awsConfig = parse_ini_file($_SERVER['HOME'] . '/.aws/config', true); $awsConfig = array('key' => $awsConfig['profile eb-cli']['aws_access_key_id'], 'secret' => $awsConfig['profile eb-cli']['aws_secret_access_key']); $s3 = new \Kwf_Util_Aws_S3($awsConfig); \Kwf_Setup::setUp(); $prodSection = $input->getOption('server'); $prodConfig = \Kwf_Config_Web::getInstance($prodSection); $bucket = $prodConfig->aws->uploadsBucket; if (!$bucket) { throw new \Exception("No aws.uploadBucket configured for '{$prodSection}'"); } $model = \Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model'); $select = new \Kwf_Model_Select(); $it = new \Kwf_Model_Iterator_Packages(new \Kwf_Model_Iterator_Rows($model, $select)); $it = new \Kwf_Iterator_ConsoleProgressBar($it); foreach ($it as $row) { $file = $row->getFileSource(); if (file_exists($file)) { if ($s3->if_object_exists($bucket, $row->id)) { echo "already existing: {$row->id}\n"; } else { echo "uploading: {$row->id}"; $contents = file_get_contents($file); $r = $s3->create_object($bucket, $row->id, array('body' => $contents, 'length' => strlen($contents), 'contentType' => $row->mime_type)); if (!$r->isOk()) { throw new \Exception($r->body); } echo " OK\n"; } } } }