You are here

public function FileQueue::bufferCommit in Purge 8.3

Commit the buffer to disk.

2 calls to FileQueue::bufferCommit()
FileQueue::destruct in src/Plugin/Purge/Queue/FileQueue.php
FileQueue::__destruct in src/Plugin/Purge/Queue/FileQueue.php
Trigger a disk commit when the object is destructed.

File

src/Plugin/Purge/Queue/FileQueue.php, line 72

Class

FileQueue
A \Drupal\purge\Plugin\Purge\Queue\QueueInterface compliant file-based queue.

Namespace

Drupal\purge\Plugin\Purge\Queue

Code

public function bufferCommit() {
  $ob = '';
  if (!file_exists($path = dirname($this->file))) {
    if (!mkdir($path, 0777, TRUE)) {
      throw new \Exception("Failed recursive mkdir() to create missing '{$path}'!");
    }
    if (!file_exists($path)) {
      throw new \Exception("Path '{$path}' still does not exist after trying mkdir()!");
    }
  }
  if (!($fh = fopen($this->file, 'w'))) {
    throw new \Exception('Unable to open file resource to ' . $this->file);
  }
  foreach ($this->buffer as $item_id => $line) {
    $ob .= $item_id . self::SEPARATOR . $line[self::DATA] . self::SEPARATOR . $line[self::EXPIRE] . self::SEPARATOR . $line[self::CREATED] . "\n";
  }
  fwrite($fh, $ob);
  fclose($fh);
}