Skip to content

Commit

Permalink
Merge pull request #1 from gheggie/fix-paths
Browse files Browse the repository at this point in the history
Use ASSET_PATH and other path utils; ensure File is created with corr…
  • Loading branch information
bhofstaetter authored Mar 25, 2019
2 parents cf85357 + 129e4a4 commit 261e0a2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/WkFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Grasenhiller\WkHtmlToX;

use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
use SilverStripe\Assets\FileNameFilter;
use SilverStripe\Assets\Folder;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Environment;
use SilverStripe\Core\Path;
use SilverStripe\View\Requirements;
use SilverStripe\View\SSViewer;

Expand Down Expand Up @@ -111,7 +113,10 @@ protected function createFile(string $fileName, string $fileClass, array $extraD
$folder = $this->getFolder();

$file = new $fileClass();
$file->setFromLocalFile('assets/' . $folder->Filename . $fileName);
$file->setFromLocalFile(
$this->getServerPath() . $fileName,
$folder->getFilename() . $fileName
);
$file->ParentID = $folder->ID;

if (count($extraData)) {
Expand All @@ -130,9 +135,10 @@ protected function createFile(string $fileName, string $fileClass, array $extraD
*/
public function setFolder(string $folderName = 'wkhtmltox') {
$this->folder = Folder::find_or_make($folderName);
$path = $this->getServerPath();

if (!file_exists($this->getServerPath())) {
mkdir($this->getServerPath(), 0777, true);
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
}

Expand All @@ -151,7 +157,9 @@ public function getFolder() {
* @return string
*/
public function getServerPath() {
return getcwd() . DIRECTORY_SEPARATOR . ASSETS_DIR . DIRECTORY_SEPARATOR . $this->getFolder()->getFileName();
return Path::normalise(
ASSETS_PATH . DIRECTORY_SEPARATOR . $this->getFolder()->getFilename()
);
}

/**
Expand Down

0 comments on commit 261e0a2

Please sign in to comment.