fixed pgsql db issue;close #38

This commit is contained in:
huangjx
2022-03-20 16:39:50 +08:00
parent f6eb5eae52
commit 2ec569e2b5
3 changed files with 22 additions and 4 deletions

View File

@@ -50,7 +50,7 @@ class YoutubeController extends Controller
$folderLink = $this->urlGenerator->linkToRoute('files.view.index', $params); $folderLink = $this->urlGenerator->linkToRoute('files.view.index', $params);
foreach ($data as $value) { foreach ($data as $value) {
$tmp = []; $tmp = [];
$extra = unserialize($value['data']); $extra = $this->dbconn->getExtra($value["data"]);
$filename = sprintf('<a class="download-file-folder" href="%s">%s</a>', $folderLink, $value['filename']); $filename = sprintf('<a class="download-file-folder" href="%s">%s</a>', $folderLink, $value['filename']);
$fileInfo = sprintf('<div class="ncd-file-info"><button id="icon-clipboard" class="icon-clipboard" data-text="%s"></button> %s | % s</div>', $extra['link'], $value['filesize'], date("Y-m-d H:i:s", $value['timestamp'])); $fileInfo = sprintf('<div class="ncd-file-info"><button id="icon-clipboard" class="icon-clipboard" data-text="%s"></button> %s | % s</div>', $extra['link'], $value['filesize'], date("Y-m-d H:i:s", $value['timestamp']));
$tmp['filename'] = array($filename, $fileInfo); $tmp['filename'] = array($filename, $fileInfo);
@@ -117,7 +117,7 @@ class YoutubeController extends Controller
} }
$row = $this->dbconn->getByGid($gid); $row = $this->dbconn->getByGid($gid);
$data = unserialize($row['data']); $data = $this->dbconn->getExtra($value["data"]);;
if (!isset($data['pid'])) { if (!isset($data['pid'])) {
if ($this->dbconn->deleteByGid($gid)) { if ($this->dbconn->deleteByGid($gid)) {
$msg = sprintf("%s is deleted from database!", $gid); $msg = sprintf("%s is deleted from database!", $gid);
@@ -152,7 +152,7 @@ class YoutubeController extends Controller
return new JSONResponse(['error' => "no gid value is received!"]); return new JSONResponse(['error' => "no gid value is received!"]);
} }
$row = $this->dbconn->getByGid($gid); $row = $this->dbconn->getByGid($gid);
$data = unserialize($row['data']); $data = $this->dbconn->getExtra($row["data"]);
if (!empty($data['link'])) { if (!empty($data['link'])) {
//$this->dbconn->deleteByGid($gid); //$this->dbconn->deleteByGid($gid);
$resp = $this->youtube->forceIPV4()->download($data['link']); $resp = $this->youtube->forceIPV4()->download($data['link']);

View File

@@ -124,4 +124,18 @@ class DbHelper
return $query->execute(); return $query->execute();
} }
public function getDBType(): string
{
return \OC::$server->getConfig()->getSystemValue('dbtype', "mysql");
}
public function getExtra($data)
{
if ($this->getDBType() == "pgsql" && is_resource($data)) {
$extra = pg_unescape_bytea(stream_get_contents($data));
return unserialize($extra);
}
return unserialize($data);
}
} }

View File

@@ -57,6 +57,10 @@ class YoutubeHelper
$this->gid = Helper::generateGID($extra['link']); $this->gid = Helper::generateGID($extra['link']);
$file = $this->getFilePath($buffer); $file = $this->getFilePath($buffer);
if ($file) { if ($file) {
$extra = serialize($extra);
if($this->dbconn->getDBType() == "pgsql"){
$extra = pg_escape_bytea($extra);
}
$data = [ $data = [
'uid' => $this->user, 'uid' => $this->user,
'gid' => $this->gid, 'gid' => $this->gid,
@@ -64,7 +68,7 @@ class YoutubeHelper
'filename' => basename($file), 'filename' => basename($file),
'status' => Helper::STATUS['ACTIVE'], 'status' => Helper::STATUS['ACTIVE'],
'timestamp' => time(), 'timestamp' => time(),
'data' => serialize($extra), 'data' => $extra,
]; ];
//save the filename as this runs only once //save the filename as this runs only once
$this->file = $file; $this->file = $file;