protected function importAttachments($item, $page)
 {
     $source = $item->getSource();
     $params = $this->importer->getParams();
     $relation = $params['FileRelation'];
     $folderPath = $params['AssetsPath'];
     $baseURL = $params['BaseUrl'];
     // Check that we should import the files and import them into the specified relation.
     if (!$relation || $page->getRelationClass($relation) != 'File') {
         return;
     }
     if ($folderPath) {
         $folder = Folder::find_or_make($folderPath);
     } else {
         $folder = Folder::get_one('Folder', "'ParentID' = 0");
     }
     $relationList = $page->{$relation}();
     foreach ($item->Files as $file) {
         $fileURL = $file['filepath'];
         // Append the site's URL if it's a relative URL.
         if (strpos($fileURL, '://') === false) {
             $fileURL = Controller::join_links($baseURL, $fileURL);
         }
         $fileName = basename($fileURL);
         $path = Controller::join_links(ASSETS_PATH, $folderPath, $fileName);
         if (file_exists($path)) {
             $SQLFilename = Controller::join_links(ASSETS_DIR, $folderPath, $fileName);
             $file = File::get_one('File', "Filename = '{$SQLFilename}'");
         } else {
             if (!($contents = file_get_contents(str_replace(' ', '%20', $fileURL)))) {
                 continue;
             }
             file_put_contents($path, $contents);
             $fileID = $folder->constructChild($fileName);
             $file = File::get_by_id('File', $fileID);
         }
         $relationList->add($file);
     }
 }
 /**
  *
  */
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     if (is_numeric($this->owner->ProfilePictureID)) {
         $profilePicture = File::get_one('File', 'ID = ' . $this->owner->ProfilePictureID);
         if (!empty($profilePicture)) {
             $profilePicture->setName(self::$ProfilePictureNamePrefix . md5($this->owner->ID) . '.' . $profilePicture->getExtension());
             $profilePicture->write(false, false, false, true);
         }
     }
 }