mirror of
https://github.com/silverstripe/silverstripe-textextraction
synced 2024-10-22 11:06:00 +02:00
FIX unlink call checks that a file exists first, and tests pass a File object
This commit is contained in:
parent
770af5cfc9
commit
6bf932e5f0
@ -140,7 +140,9 @@ abstract class FileTextExtractor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove any existing temp files with this name
|
// Remove any existing temp files with this name
|
||||||
unlink($path);
|
if (file_exists($path)) {
|
||||||
|
unlink($path);
|
||||||
|
}
|
||||||
|
|
||||||
$bytesWritten = file_put_contents($path, $file->getStream());
|
$bytesWritten = file_put_contents($path, $file->getStream());
|
||||||
if (false === $bytesWritten) {
|
if (false === $bytesWritten) {
|
||||||
|
@ -4,7 +4,6 @@ namespace SilverStripe\TextExtraction\Extractor;
|
|||||||
|
|
||||||
use SilverStripe\Assets\File;
|
use SilverStripe\Assets\File;
|
||||||
use SilverStripe\TextExtraction\Extractor\FileTextExtractor\Exception;
|
use SilverStripe\TextExtraction\Extractor\FileTextExtractor\Exception;
|
||||||
use function tempnam;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text extractor that calls pdftotext to do the conversion.
|
* Text extractor that calls pdftotext to do the conversion.
|
||||||
|
@ -25,9 +25,9 @@ class TikaRestClient extends Client
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $baseUrl
|
* @param string $baseUrl
|
||||||
* @param array $config
|
* @param array $config
|
||||||
*/
|
*/
|
||||||
public function __construct($baseUrl = '', $config = null)
|
public function __construct($baseUrl = '', $config = [])
|
||||||
{
|
{
|
||||||
$password = Environment::getEnv('SS_TIKA_PASSWORD');
|
$password = Environment::getEnv('SS_TIKA_PASSWORD');
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\TextExtraction\Tests;
|
namespace SilverStripe\TextExtraction\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\TextExtraction\Extractor\TikaServerTextExtractor;
|
use SilverStripe\TextExtraction\Extractor\TikaServerTextExtractor;
|
||||||
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
|
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
|
||||||
@ -11,6 +12,8 @@ use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
|
|||||||
*/
|
*/
|
||||||
class TikaTextExtractorTest extends SapphireTest
|
class TikaTextExtractorTest extends SapphireTest
|
||||||
{
|
{
|
||||||
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
public function testExtraction()
|
public function testExtraction()
|
||||||
{
|
{
|
||||||
$extractor = new TikaTextExtractor();
|
$extractor = new TikaTextExtractor();
|
||||||
@ -19,7 +22,10 @@ class TikaTextExtractorTest extends SapphireTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check file
|
// Check file
|
||||||
$file = dirname(__FILE__) . '/fixtures/test1.pdf';
|
$file = new File();
|
||||||
|
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
|
||||||
|
$file->write();
|
||||||
|
|
||||||
$content = $extractor->getContent($file);
|
$content = $extractor->getContent($file);
|
||||||
$this->assertContains('This is a test file with a link', $content);
|
$this->assertContains('This is a test file with a link', $content);
|
||||||
|
|
||||||
@ -37,7 +43,10 @@ class TikaTextExtractorTest extends SapphireTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check file
|
// Check file
|
||||||
$file = dirname(__FILE__) . '/fixtures/test1.pdf';
|
$file = new File();
|
||||||
|
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
|
||||||
|
$file->write();
|
||||||
|
|
||||||
$content = $extractor->getContent($file);
|
$content = $extractor->getContent($file);
|
||||||
$this->assertContains('This is a test file with a link', $content);
|
$this->assertContains('This is a test file with a link', $content);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user