public function transform($item, $parentObject, $duplicateStrategy)
 {
     $newFile = $this->getTypeForFile($item->Name);
     $folderPath = $parentObject->getRelativePath();
     $parentId = $parentObject ? $parentObject->ID : 0;
     $filter = 'ParentID = \'' . Convert::raw2sql($parentId) . '\' and Title = \'' . Convert::raw2sql($item->Name) . '\'';
     $existing = DataObject::get_one('File', $filter);
     if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_SKIP) {
         // just return the existing children
         return new TransformResult($existing, null);
     } else {
         if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) {
             $newFile = $existing;
         }
     }
     //
     $newFile->Name = $item->Name;
     $newFile->Title = $item->Name;
     $newFile->MenuTitle = $item->Name;
     //
     $size = filesize($item->FilePath);
     $details = array('size' => $size, 'name' => $item->Name, 'tmp_name' => $item->FilePath);
     $upload = new FileLoader();
     $folderPath = trim(substr($folderPath, strpos($folderPath, '/')), '/');
     try {
         $upload->loadIntoFile($details, $newFile, $folderPath);
     } catch (ValidationException $ve) {
         // ignore for now, there should really be a proper error reporting mechanism though...
         SS_Log::log("File import failed: " . $ve->getMessage(), SS_Log::WARN);
     }
     return new TransformResult($newFile, null);
 }
 public function transform($item, $parentObject, $duplicateStrategy)
 {
     // no children of docs
     $pageChildren = new DataObjectSet();
     // okay, first we'll create the new page item,
     // and map a bunch of child information across
     $newPage = new File();
     // write the content item to a location on disk
     $filename = $item->Name;
     $folderPath = $parentObject->getRelativePath();
     // see if there's an existing one, and what we should do if there is
     $parentId = $parentObject ? $parentObject->ID : 0;
     // Use the title, because SS sometimes converts filenames
     $filter = 'ParentID = \'' . Convert::raw2sql($parentId) . '\' and Title = \'' . Convert::raw2sql($filename) . '\'';
     $existing = DataObject::get_one('File', $filter);
     if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_SKIP) {
         // just return the existing children
         return new TransformResult($existing, $pageChildren);
     } else {
         if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) {
             $newPage = $existing;
         }
     }
     $folderPath = trim(substr($folderPath, strpos($folderPath, '/')), '/');
     // write it to a cache directory first
     $path = $this->getCacheDir();
     $item->streamContent($path . '/' . $filename);
     $size = filesize($path . '/' . $filename);
     $details = array('size' => $size, 'name' => $item->Name, 'tmp_name' => $path . '/' . $filename);
     $newPage->Name = $item->Name;
     $newPage->Title = $item->Title;
     $newPage->MenuTitle = $item->MenuTitle;
     // what else should we map across?
     // $newPage->MatrixId = $item->id;
     // $newPage->OriginalProperties = serialize($item->getRemoteProperties());
     $upload = new FileLoader();
     $upload->loadIntoFile($details, $newPage, $folderPath);
     return new TransformResult($newPage, $pageChildren);
 }