protected function findConnectionAssetDeltas($connection_id, $connection = false) { if (!$connection) { $connection = $this->getConnectionDetails($connection_id); } $all_local_assets = $this->getAssetsForConnection($connection_id); if (!$all_local_assets) { $all_local_assets = array(); } $all_remote_files = false; // create reference arrays $id_lookup = array(); $compare_local = array(); $compare_remote = array(); // populate local reference arrays foreach ($all_local_assets as $asset) { $id_lookup[$asset['location']] = $asset['id']; $compare_local[$asset['location']] = $asset['hash']; } // grab remotes, format $compare_remote[] as: // $compare_remote['resource_location'] => file or generated hash // // IMPORTANT: // if $all_remote_files must be keyed by service URI and each entry // must contain a value for 'size' and 'hash' -- each service Seed // should comply to that formatting but if not, fix it there, not here switch ($connection['type']) { case 'com.amazon': $s3 = new S3Seed($connection['user_id'], $connection_id); $all_remote_files = $s3->listAllFiles(); if (!is_array($all_remote_files)) { // could not get remote list. boo. abort. return false; } else { // populate remote reference array foreach ($all_remote_files as $file) { $compare_remote[$file['name']] = $file['hash']; } } } if ($all_remote_files) { //find deltas $deltas = array_diff_assoc($compare_remote, $compare_local); $deltas = array_merge($deltas, array_diff_assoc($compare_local, $compare_remote)); foreach ($deltas as $location => &$change) { if (array_key_exists($location, $compare_local) && array_key_exists($location, $compare_remote)) { $change = 'update'; // keys in both location - means hash has changed. edit local. } else { if (array_key_exists($location, $compare_remote)) { $change = 'add'; // remote key only - means new file. add local. } else { $change = 'delete'; // local key only - means file is gone. remove local. } } } $return_array = array('local_id_reference' => $id_lookup, 'remote_details' => $all_remote_files, 'deltas' => $deltas); return $return_array; } else { return false; } }
function testAuth() { if ($this->s3_key) { $s3 = new S3Seed($this->cash_user_id, $this->s3_connection_id); $starting_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertTrue(is_array($starting_acp)); $second_email = getTestEnv("S3_2_EMAIL"); $second_key = getTestEnv("S3_2_KEY"); $second_secret = getTestEnv("S3_2_SECRET"); if ($second_email && $second_key && $second_secret) { $auth_success = $s3->authorizeEmailForBucket($this->s3_bucket, $second_email); $this->assertTrue($auth_success); $changed_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertNotEqual($starting_acp, $changed_acp); // add a new connection for the second user $c = new CASHConnection($this->cash_user_id); $new_connection_id = $c->setSettings('S32', 'com.amazon', array("key" => $second_key, "secret" => $second_secret, "bucket" => $this->s3_bucket)); if ($new_connection_id) { $s32 = new S3Seed($this->cash_user_id, $new_connection_id); // now test that we do in fact have upload permission // go through the range of tests — upload, delete, verify $test_filename = dirname(__FILE__) . '/test' . $this->timestamp; $tmp_file = file_put_contents($test_filename, $this->timestamp); $result = $s32->uploadFile($test_filename, false, false); $this->assertTrue($result); $result = $s32->deleteFile('test' . $this->timestamp); $this->assertTrue($result); $full_list = $s32->listAllFiles(); $this->assertFalse(array_key_exists('test' . $this->timestamp, $full_list)); unlink(dirname(__FILE__) . '/test' . $this->timestamp); unset($s32); $acp_success = $s3->setAccessControlPolicy($this->s3_bucket, '', $starting_acp); $this->assertTrue($acp_success); $changed_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertEqual($starting_acp, $changed_acp); } else { echo 'problem adding second S3Seed'; } } } }
function testDelete() { if ($this->s3_key) { $s3 = new S3Seed($this->cash_user_id, $this->s3_connection_id); // delete both files and test return $result = $s3->deleteFile('test' . $this->timestamp); $this->assertTrue($result); $result = $s3->deleteFile('test_private' . $this->timestamp); $this->assertTrue($result); // verify they are no longer listed $full_list = $s3->listAllFiles(); $this->assertFalse(array_key_exists('test' . $this->timestamp, $full_list)); $this->assertFalse(array_key_exists('test_private' . $this->timestamp, $full_list)); } }