/**
  * @param core_kernel_classes_Resource $instance
  * @param $tmpFile
  *
  * @return \common_report_Report
  */
 public function updateInstanceAttachment($instance, $tmpFile)
 {
     $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS);
     StorageService::removeAttachedFile($instance);
     $fileResource = StorageService::storeFile($tmpFile);
     $property = new \core_kernel_classes_Property(self::PROPERTY_FILE_CONTENT);
     $instance->editPropertyValues($property, $fileResource);
     $report->setMessage(__('%s updated', $instance->getLabel()));
     $report->setData($instance);
     return $report;
 }
<?php

/**  
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; under version 2
 * of the License (non-upgradable).
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * Copyright (c) 2014 (original work) Open Assessment Technologies SA;
 *               
 * 
 */
use oat\taoBooklet\model\StorageService;
$bookletDataPath = FILES_PATH . 'taoBooklet' . DIRECTORY_SEPARATOR;
if (file_exists($bookletDataPath)) {
    helpers_File::emptyDirectory($bookletDataPath);
}
$bookletFs = tao_models_classes_FileSourceService::singleton()->addLocalSource('booklet storage', $bookletDataPath);
StorageService::setFileSystem($bookletFs);
 /**
  * Overloaded delete, also takes care about attached files
  * @throws \Exception
  * @throws \tao_models_classes_MissingRequestParameterException
  */
 public function delete()
 {
     if ($this->hasRequestParameter('uri')) {
         $instance = $this->getCurrentInstance();
         StorageService::removeAttachedFile($instance);
     }
     parent::delete();
 }