Skip to content

Commit

Permalink
Tag assignment saves changes in tag case.
Browse files Browse the repository at this point in the history
But does not log them, because they're not semantically meaningful
to the system.

Introduces two kinds of item matching: match() is used at lookup,
and equals() is used to see if there is any change, meaningful or
not.
  • Loading branch information
kohler committed Oct 28, 2023
1 parent 8928d1d commit a2c54cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/assigners/a_tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function __construct($pid, $ltag, $tag = null, $index = null, $override = null)
}
/** @return self */
function fresh() {
return new Tag_Assignable($this->pid, $this->ltag);
return new Tag_Assignable($this->pid, $this->ltag, $this->_tag);
}
/** @param Assignable $q
* @return bool */
Expand All @@ -36,6 +36,14 @@ function match($q) {
&& ($q->ltag ?? $this->ltag) === $this->ltag
&& ($q->_index ?? $this->_index) === $this->_index;
}
/** @param Assignable $q
* @return bool */
function equals($q) {
'@phan-var-force Tag_Assignable $q';
return ($q->pid ?? $this->pid) === $this->pid
&& ($q->_tag ?? $this->_tag) === $this->_tag
&& ($q->_index ?? $this->_index) === $this->_index;
}
static function load(AssignmentState $state) {
if (!$state->mark_type("tag", ["pid", "ltag"], "Tag_Assigner::make")) {
return;
Expand Down Expand Up @@ -402,10 +410,16 @@ class Tag_Assigner extends Assigner {
/** @var null|int|float
* @readonly */
public $index;
/** @var bool
* @readonly */
public $case_only;
function __construct(AssignmentItem $item, AssignmentState $state) {
parent::__construct($item, $state);
$this->tag = $item["_tag"];
$this->index = $item->post("_index");
$this->case_only = $item->existed()
&& !$item->deleted()
&& $item->before->match($item->after);
}
static function make(AssignmentItem $item, AssignmentState $state) {
$prow = $state->prow($item["pid"]);
Expand Down Expand Up @@ -461,18 +475,20 @@ function execute(AssignmentSet $aset) {
if ($this->index === null) {
$aset->stage_qe("delete from PaperTag where paperId=? and tag=?", $this->pid, $this->tag);
} else {
$aset->stage_qe("insert into PaperTag set paperId=?, tag=?, tagIndex=? on duplicate key update tagIndex=?", $this->pid, $this->tag, $this->index, $this->index);
$aset->stage_qe("insert into PaperTag set paperId=?, tag=?, tagIndex=? on duplicate key update tag=?, tagIndex=?", $this->pid, $this->tag, $this->index, $this->tag, $this->index);
}
if ($this->index !== null
&& str_ends_with($this->tag, ':')) {
$aset->register_cleanup_function("colontag", function () use ($aset) {
$aset->conf->save_refresh_setting("has_colontag", 1);
});
}
if ($aset->conf->tags()->is_track($this->tag)) {
$aset->register_update_rights();
if (!$this->case_only) {
if ($aset->conf->tags()->is_track($this->tag)) {
$aset->register_update_rights();
}
$aset->user->log_activity("Tag " . ($this->index === null ? "-" : "+") . "#{$this->tag}" . ($this->index ? "#{$this->index}" : ""), $this->pid);
}
$aset->user->log_activity("Tag " . ($this->index === null ? "-" : "+") . "#{$this->tag}" . ($this->index ? "#{$this->index}" : ""), $this->pid);
$aset->register_notify_tracker($this->pid);
}
}
8 changes: 7 additions & 1 deletion src/assignmentset.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ function match($q) {
}
return true;
}

/** @param Assignable $q
* @return bool */
function equals($q) {
return $this->match($q);
}
}

class AssignmentItem implements ArrayAccess, JsonSerializable {
Expand Down Expand Up @@ -91,7 +97,7 @@ function changed() {
return $this->after
&& ($this->deleted
? $this->existed
: !$this->existed || !$this->after->match($this->before));
: !$this->existed || !$this->after->equals($this->before));
}
/** @param bool $pre
* @param string $offset */
Expand Down

0 comments on commit a2c54cf

Please sign in to comment.