Skip to content

Commit

Permalink
use the correct Drupal 8 file methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Price authored and Andrea R Soper committed Aug 7, 2016
1 parent b9fadd4 commit a9bfcaa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ class DrupalFileContext extends SharedDrupalContext
*/
public function createFile($filename, $status = 1)
{
throw new NotUpdatedException();

$file = new File(array(), 'file');
$file->setFilename($filename);
$file->setPermanent();
/*
$file->save(); //needs to happen somewhere
*/
if($status) {
$file->setPermanent();
}
else {
$file->setTemporary();
}

$file = $this->expandFile($file);

Expand All @@ -63,10 +64,16 @@ public function createFile($filename, $status = 1)
*/
public function createFiles(TableNode $filesTable)
{
throw new NotUpdatedException();

foreach ($filesTable->getHash() as $fileHash) {
$file = (object) $fileHash;
$file = new File(array(), 'file');
$file->setFilename($fileHash['filename']);
if($fileHash['status']) {
$file->setPermanent();
}
else {
$file->setTemporary();
}
$file = $this->expandFile($file);

$this->fileCreate($file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public function findUserByName($userName)
*/
public function fileCreate($file)
{
throw new NotUpdatedException();

// Save the file and overwrite if it already exists.
$dest = file_build_uri(drupal_basename($file->GetFileUri()));
$result = file_copy($file, $dest, FILE_EXISTS_REPLACE);
Expand Down Expand Up @@ -195,8 +193,6 @@ public function fileCreate($file)
*/
public function expandFile($file)
{
throw new NotUpdatedException();

if (empty($file->getFilename()) === true) {
throw new \Exception("Can't create file with no source filename; this should be the name of a file within the MinkExtension's files_path directory.");
}
Expand All @@ -205,6 +201,10 @@ public function expandFile($file)
// files_path parameter.
$file->setFileUri(rtrim(realpath($this->getMinkParameter('files_path')), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getFilename());

$file->set('langcode', $file->language()->getId());

$file->setChangedTime(time());

// Assign authorship if none exists and `author` is passed.
/*
if (isset($file->getOwnerId()) === false && empty($file->author) === false) {
Expand Down

0 comments on commit a9bfcaa

Please sign in to comment.