refactoring
This commit is contained in:
parent
665ca9daad
commit
a246fde0e2
|
@ -422,6 +422,17 @@ class PDFStructureReader {
|
||||||
*/
|
*/
|
||||||
class PDFStructureWriter {
|
class PDFStructureWriter {
|
||||||
|
|
||||||
|
private $serverProfileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param $serverProfileName server profile name
|
||||||
|
*/
|
||||||
|
public function __construct($serverProfileName) {
|
||||||
|
$this->serverProfileName = $serverProfileName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the PDF structure to disk.
|
* Writes the PDF structure to disk.
|
||||||
*
|
*
|
||||||
|
@ -447,10 +458,10 @@ class PDFStructureWriter {
|
||||||
throw new \LAMException(_('PDF structure name not valid'),
|
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\',\'_\',\'-\'.'));
|
_('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.'));
|
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
|
// main pdf structure page
|
||||||
$saveErrors = array();
|
$saveErrors = array();
|
||||||
if(isset($_GET['submit'])) {
|
if(isset($_GET['submit'])) {
|
||||||
$writer = new PDFStructureWriter();
|
$writer = new PDFStructureWriter($_SESSION['config']->getName());
|
||||||
try {
|
try {
|
||||||
$writer->write($type->getId(), $_POST['pdfname'], $_SESSION['currentPDFStructure']);
|
$writer->write($type->getId(), $_POST['pdfname'], $_SESSION['currentPDFStructure']);
|
||||||
unset($_SESSION['currentPDFStructure']);
|
unset($_SESSION['currentPDFStructure']);
|
||||||
|
|
|
@ -106,7 +106,7 @@ class ReadStructureTest extends TestCase {
|
||||||
$reader->method('getFileName')->willReturn($file);
|
$reader->method('getFileName')->willReturn($file);
|
||||||
$structure = $reader->read('type', 'name');
|
$structure = $reader->read('type', 'name');
|
||||||
// create writer and get output XML
|
// create writer and get output XML
|
||||||
$writer = new PDFStructureWriter();
|
$writer = new PDFStructureWriter('test');
|
||||||
$xml = $writer->getXML($structure);
|
$xml = $writer->getXML($structure);
|
||||||
// compare
|
// compare
|
||||||
$this->assertEquals($originalXML, $xml);
|
$this->assertEquals($originalXML, $xml);
|
||||||
|
|
Loading…
Reference in New Issue