Skip to content

Commit

Permalink
Fix new npages/width/height columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jul 26, 2023
1 parent 0da9202 commit e6fd555
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
56 changes: 46 additions & 10 deletions src/documentinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ private function fetch_incorporate() {
$this->inactive = (int) $this->inactive;
$this->content = $this->content ?? $this->paper;
$this->paper = null;
if (isset($this->npages)) {
$this->npages = (int) $this->npages;
}
if (isset($this->width)) {
$this->width = (int) $this->width;
}
if (isset($this->height)) {
$this->height = (int) $this->height;
}
}

/** @param mysqli_result|Dbl_Result $result
Expand Down Expand Up @@ -561,11 +570,20 @@ function store_skeleton() {
if ($this->$k)
$upd[$k] = $this->$k;
}
if ($this->conf->sversion >= 276) {
foreach (["npages", "width", "height"] as $k) {
if (($this->$k ?? -1) >= 0)
$upd[$k] = $this->$k;
}
}
if ($this->_metadata) {
$upd["infoJson"] = json_encode_db($this->_metadata);
} else if ($this->infoJson) {
$upd["infoJson"] = $this->infoJson;
}
if (($upd["infoJson"] ?? "") === "{}") {
unset($upd["infoJson"]);
}

if ($this->paperStorageId > 1) {
$qv = array_values($upd);
Expand All @@ -580,6 +598,7 @@ function store_skeleton() {

if (!Dbl::is_error($result)) {
Dbl::free($result);
$this->_old_prop = null;
return true;
} else {
if ($this->conf->dblink->errno) {
Expand Down Expand Up @@ -805,16 +824,14 @@ function store_s3() {
$meta["sourcehash"] = Filer::hash_as_text($this->sourceHash);
}
}
if (($m = $this->metadata())) {
if (isset($m->width)) {
$meta["width"] = $m->width;
}
if (isset($m->height)) {
$meta["height"] = $m->height;
}
if (isset($m->npages)) {
$meta["npages"] = $m->npages;
}
if (($this->npages ?? -1) >= 0) {
$meta["npages"] = $this->npages;
}
if (($this->width ?? -1) >= 0) {
$meta["width"] = $this->width;
}
if (($this->height ?? -1) >= 0) {
$meta["height"] = $this->height;
}
$user_data = ["hotcrp" => json_encode_db($meta)];

Expand Down Expand Up @@ -1611,6 +1628,9 @@ function load_metadata() {
$this->paperId, $this->paperStorageId)
?? (object) ["infoJson" => null, "npages" => -1, "width" => -1, "height" => -1];
foreach ((array) $row as $prop => $v) {
if ($prop !== "infoJson") {
$v = (int) $v;
}
$this->$prop = $v;
}
$this->_metadata = null;
Expand Down Expand Up @@ -1684,6 +1704,22 @@ function nwords(CheckFormat $cf = null) {
}
}

/** @return ?int */
function width() {
if ($this->width === null) {
$this->load_metadata();
}
return $this->width >= 0 ? $this->width : null;
}

/** @return ?int */
function height() {
if ($this->height === null) {
$this->load_metadata();
}
return $this->height >= 0 ? $this->height : null;
}

/** @param array{attachment?:bool,no_accel?:bool,cacheable?:bool} $opts
* @return bool */
function download($opts = []) {
Expand Down
4 changes: 2 additions & 2 deletions test/t_paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ function test_document_image_dimensions() {
$doc = $paper3->document($opt->id);
xassert(!!$doc);
xassert_eqq($doc->mimetype, "image/gif");
xassert_eqq($doc->metadata()->width ?? 0, 32);
xassert_eqq($doc->metadata()->height ?? 0, 30);
xassert_eqq($doc->width(), 32);
xassert_eqq($doc->height(), 30);

$this->conf->qe("delete from PaperOption where optionId=?", $opt->id);
$sv = SettingValues::make_request($this->u_chair, [
Expand Down

0 comments on commit e6fd555

Please sign in to comment.