/** * Prepare and sanitise the table prior to saving. * * @param GamificationTableRank $table * @param array $data * * @throws \UnexpectedValueException * * @since 1.6 */ protected function prepareImage($table, $data) { if (!empty($data['image'])) { // Delete old image if I upload the new one if ($table->get('image')) { $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $filesystemHelper = new Prism\Filesystem\Helper($params); $mediaFolder = $filesystemHelper->getMediaFolder(); $file = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $mediaFolder . DIRECTORY_SEPARATOR . $table->get('image')); if (JFile::exists($file)) { JFile::delete($file); } } $table->set('image', $data['image']); } }