/**
  * @param File $file
  */
 protected function processFile(File $file)
 {
     $placeholder = Config::inst()->get('CloudAssets', 'file_placeholder');
     // 6. Local needs to be wrapped or uploaded             -> uploads as normal (via updateCloudStatus)
     $file->updateCloudStatus();
     $bucket = $file->getCloudBucket();
     if ($bucket && $bucket->hasMethod('getFileSize')) {
         $size = $bucket->getFileSize($file);
         // if the size matches the placeholder, go ahead and check the actual contents
         if ($size === strlen($placeholder)) {
             echo " Remote placeholder!";
             $content = $bucket->getContents($file);
             if ($content === $placeholder) {
                 $size = -1;
             }
         }
         if ($size < 0) {
             if ($file->isLocalMissing()) {
                 // 5. Both remote and local are missing or corrupt      -> deletes if thumbnail, flags if not (writes to missing_files.csv)
                 if ($file instanceof CloudImageCached) {
                     echo " Corrupted thumbnail deleted";
                     $file->delete();
                     return;
                 } else {
                     if (!isset($this->missing)) {
                         $this->missing = fopen(BASE_PATH . '/missing_files.csv', 'a');
                     }
                     fputcsv($this->missing, array(date('Y-m-d H:i:s'), $file->ID, $file->Filename));
                     echo " Corrupted in both locations!!!";
                     return;
                 }
             } else {
                 // 3. Remote file is a placeholder but local in tact    -> clears status and re-uploads
                 $file->CloudStatus = 'Local';
                 $file->updateCloudStatus();
             }
         }
     }
     // 1. Local file doesn't exist                          -> downloads from cloud
     // 2. Local file is a placeholder but KeepLocal is true -> downloads from cloud
     $file->createLocalIfNeeded();
     // 4. Meta data is missing                              -> restores meta
     if ($file instanceof CloudImage && !$file->getCloudMeta('Dimensions')) {
         echo " Missing metadata!";
         if ($file->isLocalMissing()) {
             $file->downloadFromCloud();
         }
         $file->setCloudMeta('Dimensions', $file->getDimensions('live'));
         $file->write();
     }
 }
 public function testDuplicateFileRecords()
 {
     CloudAssets::inst()->updateAllFiles();
     $f1 = $this->objFromFixture('File', 'file1-folder1');
     $f2 = new File();
     $f2->Filename = $f1->Filename;
     $f2->ParentID = $f1->ParentID;
     $f2->Name = $f1->Name;
     $f2->Title = $f1->Title . ' Duplicate';
     $f2->write();
     $f2->updateCloudStatus();
     $placeholder = Config::inst()->get('CloudAssets', 'file_placeholder');
     $this->assertNotEquals($placeholder, $f1->getCloudBucket()->getContents($f2));
     $this->assertEquals('Live', $f2->CloudStatus);
     $this->assertEquals($f1->CloudSize, $f2->CloudSize);
     $this->assertEquals($f1->CloudMetaJson, $f2->CloudMetaJson);
 }