Fixed detached files discovery
Searching for detached files used PostSearchService, which by default hides all hidden posts unless user explicitly asks to search for them. That way, all hidden posts were treated as detached, so their content was being removed when using the script in question.
This commit is contained in:
parent
a945a1d6db
commit
d45da1e0ae
3 changed files with 17 additions and 1 deletions
|
@ -60,7 +60,7 @@ switch ($action)
|
|||
}
|
||||
|
||||
$names = [];
|
||||
foreach (PostSearchService::getEntities(null, null, null) as $post)
|
||||
foreach (PostModel::getAll() as $post)
|
||||
{
|
||||
$names []= $post->getName();
|
||||
}
|
||||
|
|
|
@ -104,6 +104,15 @@ abstract class AbstractCrudModel implements IModel
|
|||
: null;
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
$stmt = Sql\Statements::select();
|
||||
$stmt->setColumn('*');
|
||||
$stmt->setTable(static::getTableName());
|
||||
$rows = Core::getDatabase()->fetchAll($stmt);
|
||||
return static::spawnFromDatabaseRows($rows);
|
||||
}
|
||||
|
||||
public static function getAllByIds(array $ids)
|
||||
{
|
||||
$stmt = Sql\Statements::select();
|
||||
|
|
|
@ -46,14 +46,18 @@ class ScriptTest extends AbstractTest
|
|||
public function testDetachedFilesPrint()
|
||||
{
|
||||
$post = $this->postMocker->mockSingle();
|
||||
$post->setHidden(true);
|
||||
PostModel::save($post);
|
||||
touch(Core::getConfig()->main->filesPath . DS . 'rubbish1');
|
||||
touch(Core::getConfig()->main->filesPath . DS . 'rubbish2');
|
||||
touch(Core::getConfig()->main->filesPath . DS . $post->getName());
|
||||
$output = $this->execute($this->scriptsPath . 'process-detached-files.php', ['-p']);
|
||||
$this->assert->isTrue(strpos($output, 'rubbish1') !== false);
|
||||
$this->assert->isTrue(strpos($output, 'rubbish2') !== false);
|
||||
$this->assert->isFalse(strpos($output, $post->getName()));
|
||||
$this->assert->isTrue(file_exists(Core::getConfig()->main->filesPath . DS . 'rubbish1'));
|
||||
$this->assert->isTrue(file_exists(Core::getConfig()->main->filesPath . DS . 'rubbish2'));
|
||||
$this->assert->isTrue(file_exists(Core::getConfig()->main->filesPath . DS . $post->getName()));
|
||||
}
|
||||
|
||||
public function testDetachedFilesRemove()
|
||||
|
@ -67,6 +71,7 @@ class ScriptTest extends AbstractTest
|
|||
$this->assert->isFalse(strpos($output, $post->getName()));
|
||||
$this->assert->isFalse(file_exists(Core::getConfig()->main->filesPath . DS . 'rubbish1'));
|
||||
$this->assert->isFalse(file_exists(Core::getConfig()->main->filesPath . DS . 'rubbish2'));
|
||||
$this->assert->isTrue(file_exists(Core::getConfig()->main->filesPath . DS . $post->getName()));
|
||||
}
|
||||
|
||||
public function testDetachedFilesMove()
|
||||
|
@ -81,6 +86,8 @@ class ScriptTest extends AbstractTest
|
|||
$this->assert->isFalse(strpos($output, $post->getName()));
|
||||
$this->assert->isTrue(file_exists($target . DS . 'rubbish1'));
|
||||
$this->assert->isTrue(file_exists($target . DS . 'rubbish2'));
|
||||
$this->assert->isFalse(file_exists($target . DS . DS . $post->getName()));
|
||||
$this->assert->isTrue(file_exists(Core::getConfig()->main->filesPath . DS . $post->getName()));
|
||||
unlink($target . DS . 'rubbish1');
|
||||
unlink($target . DS . 'rubbish2');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue