/** * Create container and authenticate - for destination Ceph/Swift storage * * @return Wikia\SwiftStorage storage instance */ private function destConn() { $city_id = $this->imageSyncQueueItem->city_id; if (empty($this->dest_container[$city_id])) { if ($city_id == 0) { global $wgBlogAvatarSwiftContainer, $wgBlogAvatarSwiftPathPrefix; $this->dest_container[$city_id] = \Wikia\SwiftStorage::newFromContainer($wgBlogAvatarSwiftContainer, $wgBlogAvatarSwiftPathPrefix, $this->mDC_dst); } else { $this->dest_container[$city_id] = \Wikia\SwiftStorage::newFromWiki($city_id, $this->mDC_dst); } } return $this->dest_container[$city_id]; }
/** * Set up the config variables */ private function init() { global $wgUploadDirectory, $wgDBname, $wgCityId; $this->setupMd5Cache(); $dcs = explode(',', $this->getOption('dc', 'sjc,res')); foreach ($dcs as $dc) { // force a different bucket name via --bucket $swiftBackend = \Wikia\SwiftStorage::newFromContainer('common', '/avatars', $dc); $remotePath = $swiftBackend->getUrl(''); $this->output("Migrating avatars - <{$this->uploadDir}> -> <{$remotePath}> [dc: {$dc}]...\n"); $this->swiftBackends[$dc] = $swiftBackend; $this->timePerDC[$dc] = 0; } }
/** * Set up the config variables */ private function init() { global $wgUploadDirectory, $wgDBname, $wgCityId; $this->shortBucketNameFixed = $this->fixShortBucketName(); $bucketName = $this->getOption('bucket', false); $dcs = explode(',', $this->getOption('dc', 'sjc,res')); foreach ($dcs as $dc) { if (!is_string($bucketName)) { // use bucket name taken from wiki upload path $swiftBackend = \Wikia\SwiftStorage::newFromWiki($wgCityId, $dc); } else { // force a different bucket name via --bucket $swiftBackend = \Wikia\SwiftStorage::newFromContainer($bucketName, '/images', $dc); } $remotePath = $swiftBackend->getUrl(''); $this->output("Migrating images on {$wgDBname} - <{$wgUploadDirectory}> -> <{$remotePath}> [dc: {$dc}]...\n"); $this->swiftBackends[$dc] = $swiftBackend; $this->timePerDC[$dc] = 0; } }
public function testStoreAndRemove() { global $IP; $swift = \Wikia\SwiftStorage::newFromContainer(self::CONTAINER); // upload the file $localFile = "{$IP}/skins/shared/images/sprite.png"; $remoteFile = sprintf('Test_%s.png', time()); $this->assertFalse($swift->exists($remoteFile), 'File should not exist before the upload'); $res = $swift->store($localFile, $remoteFile, [], 'image/png'); $this->assertTrue($res->isOK(), 'Upload should be done'); // check the uploaded file $url = $swift->getUrl($remoteFile); $this->assertStringEndsWith('/' . self::CONTAINER . '/' . $remoteFile, $url); $this->assertTrue(Http::get($url, 'default', ['noProxy' => true]) !== false, 'Uploaded image should return HTTP 200 - ' . $url); $this->assertTrue($swift->exists($remoteFile), 'File should exist'); // npw remove the file $res = $swift->remove($remoteFile); $this->assertTrue($res->isOK(), 'Delete should be done'); $this->assertTrue(Http::get($url, 'default', ['noProxy' => true]) === false, 'Removed image should return HTTP 404 - ' . $url); $this->assertFalse($swift->exists($remoteFile), 'File should not exist after the delete'); }
/** * Get Swift storage instance for avatars * * @return \Wikia\SwiftStorage storage instance */ public function getSwiftStorage() { global $wgBlogAvatarSwiftContainer, $wgBlogAvatarSwiftPathPrefix; return \Wikia\SwiftStorage::newFromContainer($wgBlogAvatarSwiftContainer, $wgBlogAvatarSwiftPathPrefix); }