Skip to content

Commit

Permalink
Update #11, Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
dusta committed Jan 24, 2019
1 parent cb80f10 commit 30baadc
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions examples/example1/app/Model/FileStorage/Drivers/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public function get($adapter, $path, $cache = false)
return $this->methodResult(false);
}

$row = $this->baseClass->db->select('files', '*', ['file_path' => $path, 'file_adapter' => $adapter])->result();
$row = $this->db->select('files', '*', ['file_path' => $path, 'file_adapter' => $adapter])->result();
if (empty($row['file_id'])) {
return $this->methodResult(false);
}

if ($cache != false) {
if ($cache === true) {
$row['cache'] = $this->baseClass->db->select('file_cache', '*', ['file_id' => $row['file_id']])->results();
$row['cache'] = $this->db->select('file_cache', '*', ['file_id' => $row['file_id']])->results();
} else {
$row['cache'] = $this->baseClass->db->select('file_cache', '*', ['file_cache_path' => $cache])->result();
$row['cache'] = $this->db->select('file_cache', '*', ['file_cache_path' => $cache])->result();
}
}

Expand All @@ -54,7 +54,7 @@ public function put($adapter, $path, $mime, $stream = false)
return $this->methodResult(false, ['response' => 'Taki obraz już istnieje']);
}

$getLastInsertId = $this->baseClass->db->pdoQuery('INSERT INTO `files` (`file_adapter`, `file_path`, `file_mime`) VALUES (?,?,?)', [$adapter, $path, $mime])->getLastInsertId();
$getLastInsertId = $this->db->pdoQuery('INSERT INTO `files` (`file_adapter`, `file_path`, `file_mime`) VALUES (?,?,?)', [$adapter, $path, $mime])->getLastInsertId();
return $this->methodResult(true, ['lastInsertId' => $getLastInsertId]);
}

Expand All @@ -69,13 +69,13 @@ public function put($adapter, $path, $mime, $stream = false)
*/
public function cache($adapter, $originalPath, $cachePath, $mime, $stream = false)
{
$row = $this->baseClass->db->select('files', '*', ['file_path' => $originalPath])->result();
$row = $this->db->select('files', '*', ['file_path' => $originalPath])->result();
if (empty($row['file_id'])) {
$put = $this->put($adapter, $originalPath, $mime, $stream);
$row['file_id'] = $put['lastInsertId'];
}

$cache = $this->baseClass->db->select('file_cache', '*', ['file_cache_path' => $cachePath])->result();
$cache = $this->db->select('file_cache', '*', ['file_cache_path' => $cachePath])->result();
if (empty($cache['id']) and !empty($row['file_id'])) {
$data = [
'file_id' => $row['file_id'],
Expand All @@ -88,7 +88,7 @@ public function cache($adapter, $originalPath, $cachePath, $mime, $stream = fals
// $data['file_cache_metadata'] = json_encode($metadata->get());
// }

$getLastInsertId = $this->baseClass->db->insert('file_cache', $data);
$getLastInsertId = $this->db->insert('file_cache', $data);
return $this->methodResult(true, ['lastInsertId' => $getLastInsertId]);
}

Expand All @@ -104,15 +104,15 @@ public function cache($adapter, $originalPath, $cachePath, $mime, $stream = fals
public function drop($adapter, $path)
{
try {
$this->baseClass->db->start();
$row = $this->baseClass->db->pdoQuery('SELECT * FROM files WHERE `file_path` = ?', [$path])->result();
$this->db->start();
$row = $this->db->pdoQuery('SELECT * FROM files WHERE `file_path` = ?', [$path])->result();

$affectedRows = $this->baseClass->db->delete('file_cache', ['file_id' => $row['file_id']])->affectedRows();
$affectedRows = $this->baseClass->db->delete('files', ['file_id' => $row['file_id']])->affectedRows();
$affectedRows = $this->db->delete('file_cache', ['file_id' => $row['file_id']])->affectedRows();
$affectedRows = $this->db->delete('files', ['file_id' => $row['file_id']])->affectedRows();

$this->baseClass->db->end();
$this->db->end();
} catch (\Exception $e) {
$this->baseClass->db->back();
$this->db->back();
return $this->methodResult(false, ['response' => $e->getMessages()]);
}

Expand Down

0 comments on commit 30baadc

Please sign in to comment.