/** * @param $strPrefix * @param \Contao\DataContainer $dc * @return string */ public function saveCbValidateFilePrefix($strPrefix, \Contao\DataContainer $dc) { $i = 0; if ($strPrefix != '') { // >= php ver 5.4 $transliterator = Transliterator::createFromRules(':: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD); $strPrefix = $transliterator->transliterate($strPrefix); $strPrefix = str_replace('.', '_', $strPrefix); $arrOptions = array('column' => array('tl_gallery_creator_pictures.pid=?'), 'value' => array($dc->id), 'order' => 'sorting ASC'); $objPicture = MCupic\GalleryCreatorPicturesModel::findAll($arrOptions); if ($objPicture !== null) { while ($objPicture->next()) { $objFile = \FilesModel::findOneByUuid($objPicture->uuid); if ($objFile !== null) { if (is_file(TL_ROOT . '/' . $objFile->path)) { $oFile = new File($objFile->path); $i++; while (is_file($oFile->dirname . '/' . $strPrefix . '_' . $i . '.' . strtolower($oFile->extension))) { $i++; } $oldPath = $oFile->dirname . '/' . $strPrefix . '_' . $i . '.' . strtolower($oFile->extension); $newPath = str_replace(TL_ROOT . '/', '', $oldPath); // rename file if ($oFile->renameTo($newPath)) { $objPicture->path = $oFile->path; $objPicture->save(); \Message::addInfo(sprintf('Picture with ID %s has been renamed to %s.', $objPicture->id, $newPath)); } } } } } } return ''; }