public static function renameDocument($args)
 {
     $fileId = intval(@$args['file_id']);
     $name = @$_POST['name'];
     $file = new File($fileId);
     $l = new \OC_L10n('documents');
     if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) {
         if ($file->renameTo($name)) {
             // TODO: propagate to other clients
             \OCP\JSON::success();
             return;
         }
     }
     \OCP\JSON::error(array('message' => $l->t('You don\'t have permission to rename this document')));
 }
 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     $outFile = new \File(self::OUT_FILE_PATHNAME);
     $pidFile = new \File(self::PID_FILE_PATHNAME);
     $output = $outFile->getContent();
     $pid = $pidFile->getContent();
     // We send special signal 0 to test for existance of the process which is much more bullet proof than
     // using anything like shell_exec() wrapped ps/pgrep magic (which is not available on all systems).
     $isRunning = (bool) posix_kill($pid, 0);
     $startTime = new \DateTime();
     $startTime->setTimestamp(filectime(TL_ROOT . '/' . self::PID_FILE_PATHNAME));
     $endTime = new \DateTime();
     $endTime->setTimestamp($isRunning ? time() : filemtime(TL_ROOT . '/' . self::OUT_FILE_PATHNAME));
     $uptime = $endTime->diff($startTime);
     $uptime = $uptime->format('%h h %I m %S s');
     if (!$isRunning && \Input::getInstance()->post('close')) {
         $outFile->renameTo(UpdatePackagesController::OUTPUT_FILE_PATHNAME);
         $pidFile->delete();
         $this->redirect('contao/main.php?do=composer&update=database');
     } else {
         if ($isRunning && \Input::getInstance()->post('terminate')) {
             posix_kill($pid, SIGTERM);
             $this->reload();
         }
     }
     $converter = new ConsoleColorConverter();
     $output = $converter->parse($output);
     if (\Environment::getInstance()->isAjaxRequest) {
         header('Content-Type: application/json; charset=utf-8');
         echo json_encode(array('output' => $output, 'isRunning' => $isRunning, 'uptime' => $uptime));
         exit;
     } else {
         $template = new \BackendTemplate('be_composer_client_detached');
         $template->output = $output;
         $template->isRunning = $isRunning;
         $template->uptime = $uptime;
         return $template->parse();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     $outFile = new \File(self::OUT_FILE_PATHNAME);
     $pidFile = new \File(self::PID_FILE_PATHNAME);
     $output = $outFile->getContent();
     $pid = $pidFile->getContent();
     $isRunning = $this->isPidStillRunning($pid);
     $startTime = new \DateTime();
     $startTime->setTimestamp(filectime(TL_ROOT . '/' . self::PID_FILE_PATHNAME));
     $endTime = new \DateTime();
     $endTime->setTimestamp($isRunning ? time() : filemtime(TL_ROOT . '/' . self::OUT_FILE_PATHNAME));
     $uptime = $endTime->diff($startTime);
     $uptime = $uptime->format('%h h %I m %S s');
     if (!$isRunning && \Input::getInstance()->post('close')) {
         $outFile->renameTo(UpdatePackagesController::OUTPUT_FILE_PATHNAME);
         $pidFile->delete();
         $this->redirect('contao/main.php?do=composer&update=database');
     } else {
         if ($isRunning && \Input::getInstance()->post('terminate')) {
             $this->killPid($pid);
             $this->reload();
         }
     }
     $converter = new ConsoleColorConverter();
     $output = $converter->parse($output);
     if (\Environment::getInstance()->isAjaxRequest) {
         header('Content-Type: application/json; charset=utf-8');
         echo json_encode(array('output' => $output, 'isRunning' => $isRunning, 'uptime' => $uptime));
         exit;
     } else {
         $template = new \BackendTemplate('be_composer_client_detached');
         $template->output = $output;
         $template->isRunning = $isRunning;
         $template->uptime = $uptime;
         return $template->parse();
     }
 }
Example #4
0
 /**
  * Rotate the log files
  */
 public function rotateLogs()
 {
     $arrFiles = preg_grep('/\\.log$/', scan(TL_ROOT . '/system/logs'));
     foreach ($arrFiles as $strFile) {
         $objFile = new \File('system/logs/' . $strFile . '.9', true);
         // Delete the oldest file
         if ($objFile->exists()) {
             $objFile->delete();
         }
         // Rotate the files (e.g. error.log.4 becomes error.log.5)
         for ($i = 8; $i > 0; $i--) {
             $strGzName = 'system/logs/' . $strFile . '.' . $i;
             if (file_exists(TL_ROOT . '/' . $strGzName)) {
                 $objFile = new \File($strGzName, true);
                 $objFile->renameTo('system/logs/' . $strFile . '.' . ($i + 1));
             }
         }
         // Add .1 to the latest file
         $objFile = new \File('system/logs/' . $strFile, true);
         $objFile->renameTo('system/logs/' . $strFile . '.1');
     }
 }
 public function moveAttachments(\DataContainer $objDc)
 {
     if (($objSubmission = \HeimrichHannot\Submissions\SubmissionModel::findByPk($objDc->id)) === null) {
         return false;
     }
     if (($objSubmissionArchive = $objSubmission->getRelated('pid')) === null) {
         return false;
     }
     if (!$objSubmission->attachments) {
         return false;
     }
     $strSubFolder = Tokens::replace($objSubmissionArchive->attachmentSubFolderPattern, $objSubmission);
     $objFileModels = \FilesModel::findMultipleByUuids(deserialize($objSubmission->attachments, true));
     if ($objFileModels === null || $strSubFolder == '') {
         return false;
     }
     $strFolder = $objSubmissionArchive->attachmentUploadFolder;
     if (\Validator::isUuid($objSubmissionArchive->attachmentUploadFolder)) {
         if (($strFolder = Files::getPathFromUuid($objSubmissionArchive->attachmentUploadFolder)) === null) {
             return false;
         }
     }
     $strTarget = rtrim($strFolder, '/') . '/' . ltrim($strSubFolder, '/');
     while ($objFileModels->next()) {
         if (!file_exists(TL_ROOT . '/' . $objFileModels->path)) {
             continue;
         }
         $objFile = new \File($objFileModels->path, true);
         $objFile->renameTo($strTarget . '/' . basename($objFile->value));
     }
 }
Example #6
0
 /**
  * insert a new entry in tl_gallery_creator_pictures
  *
  * @param integer
  * @param string
  * $intAlbumId - albumId
  * $strFilepath - filepath -> files/gallery_creator_albums/albumalias/filename.jpg
  * @return bool
  */
 public static function createNewImage($intAlbumId, $strFilepath)
 {
     //get the file-object
     $objFile = new \File($strFilepath);
     if (!$objFile->isGdImage) {
         return false;
     }
     //get the album-object
     $objAlbum = \MCupic\GalleryCreatorAlbumsModel::findById($intAlbumId);
     // get the assigned album directory
     $objFolder = \FilesModel::findByUuid($objAlbum->assignedDir);
     $assignedDir = null;
     if ($objFolder !== null) {
         if (is_dir(TL_ROOT . '/' . $objFolder->path)) {
             $assignedDir = $objFolder->path;
         }
     }
     if ($assignedDir == null) {
         die('Aborted Script, because there is no upload directory assigned to the Album with ID ' . $intAlbumId);
     }
     //check if the file ist stored in the album-directory or if it is stored in an external directory
     $blnExternalFile = false;
     if (\Input::get('importFromFilesystem')) {
         $blnExternalFile = strstr($objFile->dirname, $assignedDir) ? false : true;
     }
     //get the album object and the alias
     $strAlbumAlias = $objAlbum->alias;
     //db insert
     $objImg = new \GalleryCreatorPicturesModel();
     $objImg->tstamp = time();
     $objImg->pid = $objAlbum->id;
     $objImg->externalFile = $blnExternalFile ? "1" : "";
     $objImg->save();
     if ($objImg->id) {
         $insertId = $objImg->id;
         // Get the next sorting index
         $objImg_2 = \Database::getInstance()->prepare('SELECT MAX(sorting)+10 AS maximum FROM tl_gallery_creator_pictures WHERE pid=?')->execute($objAlbum->id);
         $sorting = $objImg_2->maximum;
         // If filename should be generated
         if (!$objAlbum->preserve_filename && $blnExternalFile === false) {
             $newFilepath = sprintf('%s/alb%s_img%s.%s', $assignedDir, $objAlbum->id, $insertId, $objFile->extension);
             $objFile->renameTo($newFilepath);
         }
         // GalleryCreatorImagePostInsert - HOOK
         // übergibt die id des neu erstellten db-Eintrages ($lastInsertId)
         if (isset($GLOBALS['TL_HOOKS']['galleryCreatorImagePostInsert']) && is_array($GLOBALS['TL_HOOKS']['galleryCreatorImagePostInsert'])) {
             foreach ($GLOBALS['TL_HOOKS']['galleryCreatorImagePostInsert'] as $callback) {
                 $objClass = self::importStatic($callback[0]);
                 $objClass->{$callback}[1]($insertId);
             }
         }
         if (is_file(TL_ROOT . '/' . $objFile->path)) {
             //get the userId
             $userId = '0';
             if (TL_MODE == 'BE') {
                 $userId = \BackendUser::getInstance()->id;
             }
             // the album-owner is automaticaly the image owner, if the image was uploaded by a by a frontend user
             if (TL_MODE == 'FE') {
                 $userId = $objAlbum->owner;
             }
             // Get the FilesModel
             $objFileModel = \FilesModel::findByPath($objFile->path);
             //finally save the new image in tl_gallery_creator_pictures
             $objPicture = \GalleryCreatorPicturesModel::findByPk($insertId);
             $objPicture->uuid = $objFileModel->uuid;
             $objPicture->owner = $userId;
             $objPicture->date = $objAlbum->date;
             $objPicture->sorting = $sorting;
             $objPicture->save();
             \System::log('A new version of tl_gallery_creator_pictures ID ' . $insertId . ' has been created', __METHOD__, TL_GENERAL);
             //check for a valid preview-thumb for the album
             $objAlbum = \MCupic\GalleryCreatorAlbumsModel::findByAlias($strAlbumAlias);
             if ($objAlbum !== null) {
                 if ($objAlbum->thumb == "") {
                     $objAlbum->thumb = $insertId;
                     $objAlbum->save();
                 }
             }
             return true;
         } else {
             if ($blnExternalFile === true) {
                 $_SESSION['TL_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['link_to_not_existing_file'], $strFilepath);
             } else {
                 $_SESSION['TL_ERROR'][] = sprintf($GLOBALS['TL_LANG']['ERR']['uploadError'], $strFilepath);
             }
             \System::log('Unable to create the new image in: ' . $strFilepath . '!', __METHOD__, TL_ERROR);
         }
     }
     return false;
 }
 /**
  * @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 '';
 }
 /**
  * move images in the filesystem, when cutting/pasting images from one album into another
  *
  * @param DC_Table $dc
  */
 public function onCutCb(DC_Table $dc)
 {
     if (!isset($_SESSION['gallery_creator']['SOURCE_ALBUM_ID'])) {
         return;
     }
     // Get sourceAlbumObject
     $objSourceAlbum = GalleryCreatorAlbumsModel::findByPk($_SESSION['gallery_creator']['SOURCE_ALBUM_ID']);
     unset($_SESSION['gallery_creator']['SOURCE_ALBUM_ID']);
     // Get pictureToMoveObject
     $objPictureToMove = GalleryCreatorPicturesModel::findByPk(Input::get('id'));
     if ($objSourceAlbum === null || $objPictureToMove === null) {
         return;
     }
     if (Input::get('mode') == '1') {
         // Paste after existing file
         $objTargetAlbum = GalleryCreatorPicturesModel::findByPk(Input::get('pid'))->getRelated('pid');
     } elseif (Input::get('mode') == '2') {
         // Paste on top
         $objTargetAlbum = GalleryCreatorAlbumsModel::findByPk(Input::get('pid'));
     }
     if ($objTargetAlbum === null) {
         return;
     }
     if ($objSourceAlbum->id == $objTargetAlbum->id) {
         return;
     }
     $objFile = FilesModel::findByUuid($objPictureToMove->uuid);
     $objTargetFolder = FilesModel::findByUuid($objTargetAlbum->assignedDir);
     $objSourceFolder = FilesModel::findByUuid($objSourceAlbum->assignedDir);
     if ($objFile === null || $objTargetFolder === null || $objSourceFolder === null) {
         return;
     }
     // Return if it is an external file
     if (false === strpos($objFile->path, $objSourceFolder->path)) {
         return;
     }
     $strDestination = $objTargetFolder->path . '/' . basename($objFile->path);
     if ($strDestination != $objFile->path) {
         $oFile = new File($objFile->path);
         // Move file to the target folder
         if ($oFile->renameTo($strDestination)) {
             $objPictureToMove->path = $strDestination;
             $objPictureToMove->save();
         }
     }
 }