Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(Torrent): Clean temp upload torrent file after success upload
Browse files Browse the repository at this point in the history
1. Remove property `output` of \Rid\Base\Application
2. Fix can't Log after commit 2ffc1ac
3. Check if this torrent is exist or not before insert.
4. Clean temp torrent file after upload, and will clean saved torrent when get error
  • Loading branch information
Rhilip committed Feb 7, 2019
1 parent 7c61422 commit ffca1e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
15 changes: 11 additions & 4 deletions apps/models/form/TorrentUploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ public function flush()
{
$this->makePrivateTorrent();

// Check if this torrent is exist or not before insert.
$count = app()->pdo->createCommand('SELECT COUNT(*) FROM torrents WHERE info_hash = :info_hash')->bindParams([
'info_hash' => $this->info_hash
])->queryScalar();
if ($count > 0) throw new \Exception('std_torrent_existed');

// TODO update torrent status based on user class or their owned torrents count

app()->pdo->beginTransaction();
Expand Down Expand Up @@ -198,15 +204,16 @@ public function flush()

app()->pdo->commit();
} catch (\Exception $e) {
app()->pdo->rollback();
if (isset($dump_status) && $dump_status == false) {
// Delete the saved torrent file when torrent save success but still get Exception on other side
if (isset($dump_status) && $dump_status == true) {
unlink(Torrent::TorrentFileLoc($this->id));
}

//if ($e->getCode() == 23000)
// throw new \Exception('std_torrent_existed');
app()->pdo->rollback();

throw $e;
} finally {
unlink($this->file->getPathname()); // Remove temp file
}
}

Expand Down
1 change: 0 additions & 1 deletion framework/Base/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* @property \Rid\Log\Log $log
* @property \Rid\Console\Input $input
* @property \Rid\Console\Output $output
* @property \Rid\Http\Route $route
* @property \Rid\Http\Request|\Rid\Http\Compatible\Request $request
* @property \Rid\Http\Response|\Rid\Http\Compatible\Response $response
Expand Down
2 changes: 1 addition & 1 deletion framework/Log/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function debug($message, array $context = [])
public function log($level, $message, array $context = [])
{
if (in_array($level, $this->level)) {
return $this->println($level, $message, $context); // FIXME method is not found
return $this->write($level, $message, $context); // FIXME method is not found
}
return false;
}
Expand Down

0 comments on commit ffca1e7

Please sign in to comment.