/** * Main function, rendering the content of the rename form * * @return void */ function main() { global $LANG; $content = ''; // Cleaning and checking target if ($this->pObj->file[0]) { $this->file = tx_dam::file_compileInfo($this->pObj->file[0]); $this->meta = tx_dam::meta_getDataForFile($this->file); } elseif ($id = intval($this->pObj->record['tx_dam'][0])) { $this->meta = tx_dam::meta_getDataByUid($id); $this->file = tx_dam::file_compileInfo($this->meta); } if (!is_array($this->meta)) { $fileType = tx_dam::file_getType($this->file); $this->meta = array_merge($this->file, $fileType); $this->meta['uid'] = 0; } if ($this->file['file_accessable']) { if (is_array($this->pObj->data) and $this->pObj->data['file_name']) { $error = tx_dam::process_renameFile($this->file, $this->pObj->data['file_name'], $this->pObj->data); if ($error) { $content .= $GLOBALS['SOBE']->getMessageBox($LANG->getLL('error'), htmlspecialchars($error), $this->pObj->buttonBack(0), 2); } else { $this->pObj->redirect(); } } else { $content .= $this->renderForm(); } } else { // this should have happen in index.php already $content .= $this->pObj->accessDeniedMessageBox($this->file['file_name']); } return $content; }
/** * tx_dam::process_renameFile() */ public function test_process_renameFile() { $this->removeFixtureTempFiles(); $this->removeIndexSetup(); $this->removeFixturesFromIndex(); $this->addFixturePathToFilemount(); $filepath = $this->getFixtureTempFilename(); $uid = tx_dam::file_isIndexed($filepath); self::assertNoUID($uid, 'File index found, but shouldn\'t'); tx_dam::config_setValue('setup.indexing.auto', true); $indexed = tx_dam::index_autoProcess($filepath, $reindex = false); self::assertTrue(isset($indexed['isIndexed']), 'File not indexed'); $uid = $indexed['fields']['uid']; $filepathNew = $filepath . '.doc'; $error = tx_dam::process_renameFile($filepath, tx_dam::file_basename($filepathNew)); if ($error) { debug($error); } self::assertTrue(is_file($filepathNew), 'File not renamed'); $uid2 = tx_dam::file_isIndexed($filepathNew); self::assertUID($uid2, 'File index not found'); self::assertEquals(intval($uid), intval($uid2), 'Wrong uid: ' . $uid . ' - ' . $uid2); $data = tx_dam::meta_getDataByUid($uid); self::assertEquals($data['file_name'], tx_dam::file_basename($filepathNew), 'Wrong file name ' . $indexed['fields']['file_name'] . ' != ' . tx_dam::file_basename($filepathNew)); $this->removeFixturePathFromFilemount(); $this->removeFixturesFromIndex(); $this->removeIndexSetup(); $this->removeFixtureTempFiles(); }