refactoring
This commit is contained in:
parent
665ca9daad
commit
a246fde0e2
|
@ -422,6 +422,17 @@ class PDFStructureReader {
|
|||
*/
|
||||
class PDFStructureWriter {
|
||||
|
||||
private $serverProfileName;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param $serverProfileName server profile name
|
||||
*/
|
||||
public function __construct($serverProfileName) {
|
||||
$this->serverProfileName = $serverProfileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the PDF structure to disk.
|
||||
*
|
||||
|
@ -447,10 +458,10 @@ class PDFStructureWriter {
|
|||
throw new \LAMException(_('PDF structure name not valid'),
|
||||
_('The name for that PDF-structure you submitted is not valid. A valid name must consist of the following characters: \'a-z\',\'A-Z\',\'0-9\',\'_\',\'-\'.'));
|
||||
}
|
||||
if(!is_writable(dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName())) {
|
||||
if(!is_writable(dirname(__FILE__) . '/../config/pdf/' . $this->serverProfileName)) {
|
||||
throw new \LAMException(_('Could not save PDF structure, access denied.'));
|
||||
}
|
||||
return dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml';
|
||||
return dirname(__FILE__) . '/../config/pdf/' . $this->serverProfileName . '/' . $name . '.' . $typeId . '.xml';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -135,7 +135,7 @@ if (!empty($_POST['form_submit'])) {
|
|||
// main pdf structure page
|
||||
$saveErrors = array();
|
||||
if(isset($_GET['submit'])) {
|
||||
$writer = new PDFStructureWriter();
|
||||
$writer = new PDFStructureWriter($_SESSION['config']->getName());
|
||||
try {
|
||||
$writer->write($type->getId(), $_POST['pdfname'], $_SESSION['currentPDFStructure']);
|
||||
unset($_SESSION['currentPDFStructure']);
|
||||
|
|
|
@ -106,7 +106,7 @@ class ReadStructureTest extends TestCase {
|
|||
$reader->method('getFileName')->willReturn($file);
|
||||
$structure = $reader->read('type', 'name');
|
||||
// create writer and get output XML
|
||||
$writer = new PDFStructureWriter();
|
||||
$writer = new PDFStructureWriter('test');
|
||||
$xml = $writer->getXML($structure);
|
||||
// compare
|
||||
$this->assertEquals($originalXML, $xml);
|
||||
|
|
Loading…
Reference in New Issue