-
Notifications
You must be signed in to change notification settings - Fork 23
fix: refactor getTemplateVar and getTemplateVars methods for improved… #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yama
wants to merge
6
commits into
main
Choose a base branch
from
fix/forum-t2032
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
618adb3
fix: refactor getTemplateVar and getTemplateVars methods for improved…
yama 8f47c7d
feat: Codex用の新しいスキル「exec-plan」と「issue-resolver」を追加し、ExecPlanの品質チェックリス…
yama 139a606
fix: 実行ルールの修正とdraft-planセクションの明確化
yama 031d6c2
feat: issue-resolverスキルの実行ルールを更新し、URL取得手順を明確化
yama 10480c9
feat: issue-resolverスキルの実行ルールを更新し、調査報告と修正手順の明確化
yama 5e069e2
Merge branch 'feature/skills' into fix/forum-t2032
yama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4715,6 +4715,7 @@ public function mb_strftime($format = '%Y/%m/%d', $timestamp = '') | |||||||||||
|
|
||||||||||||
| // Modified by Raymond for TV - Orig Modified by Apodigm - DocVars | ||||||||||||
| # returns a single TV record. $idnames - can be an id or name that belongs the template that the current document is using | ||||||||||||
| # $fields is kept for backward compatibility but no longer used (always selects all columns) | ||||||||||||
| public function getTemplateVar($idname = '', $fields = '*', $docid = '', $published = 1) | ||||||||||||
| { | ||||||||||||
| if ($idname == '') { | ||||||||||||
|
|
@@ -4726,97 +4727,89 @@ public function getTemplateVar($idname = '', $fields = '*', $docid = '', $publis | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
| # returns an array of TV records. $idnames - can be an id or name that belongs the template that the current document is using | ||||||||||||
| # $fields is kept for backward compatibility but no longer used (always selects all columns) | ||||||||||||
| public function getTemplateVars($idnames = '*', $fields = '*', $docid = '', $published = 1, $sort = 'rank', $dir = 'ASC') | ||||||||||||
| { | ||||||||||||
| // get document record | ||||||||||||
| if ($docid === '' && $this->documentIdentifier) { | ||||||||||||
| $docid = $this->documentIdentifier; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ($this->array_get($this->previewObject, 'template')) { | ||||||||||||
| $resource = $this->getDocument($docid, '*', null); //Ignore published when the preview. | ||||||||||||
| $resource['template'] = $this->previewObject['template']; | ||||||||||||
| } elseif ($docid == $this->documentIdentifier) { | ||||||||||||
| $resource = $this->documentObject; | ||||||||||||
| } else { | ||||||||||||
| $resource = $this->getDocument($docid, '*', $published); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| $resource = $this->getResourceForTV($docid, $published); | ||||||||||||
| if (!$resource) { | ||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
| if (!$resource['template']) { | ||||||||||||
| $result = []; | ||||||||||||
| foreach ($resource as $key => $value) { | ||||||||||||
| if ($idnames === '*' || (is_string($idnames) && in_array($key, explode(',', $idnames)))) { | ||||||||||||
| $result[] = ['name' => $key, 'value' => $value]; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| return $result; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ($fields === '*' || $fields === '') { | ||||||||||||
| $fields = "tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value"; | ||||||||||||
| } else { | ||||||||||||
| $fields = sprintf( | ||||||||||||
| "%s, IF(tvc.value!='',tvc.value,tv.default_text) as value", | ||||||||||||
| array_map( | ||||||||||||
| function ($v) { | ||||||||||||
| return 'tv.' . $v; | ||||||||||||
| }, | ||||||||||||
| explode(',', $fields) | ||||||||||||
| ) | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| // built-in resource fields | ||||||||||||
| $result = $this->collectResourceFields($resource, $idnames); | ||||||||||||
|
|
||||||||||||
| if (is_array($idnames) && !empty($idnames)) { | ||||||||||||
| $idnames = sprintf( | ||||||||||||
| "'%s'", | ||||||||||||
| implode("','", db()->escape($idnames)) | ||||||||||||
| // user-defined template variables | ||||||||||||
| if ($resource['template']) { | ||||||||||||
| $where = $this->buildTVWhereClause($idnames); | ||||||||||||
| $orderby = $sort | ||||||||||||
| ? sprintf('%s %s', $this->join(',', explode(',', $sort), 'tv.'), $dir) | ||||||||||||
| : ''; | ||||||||||||
|
|
||||||||||||
| $rs = db()->select( | ||||||||||||
| "tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value", | ||||||||||||
| [ | ||||||||||||
| '[+prefix+]site_tmplvars tv', | ||||||||||||
| 'INNER JOIN [+prefix+]site_tmplvar_templates tvtpl ON tvtpl.tmplvarid = tv.id', | ||||||||||||
| sprintf( | ||||||||||||
| "LEFT JOIN [+prefix+]site_tmplvar_contentvalues tvc ON tvc.tmplvarid=tv.id AND tvc.contentid='%s'", | ||||||||||||
| $docid | ||||||||||||
| ) | ||||||||||||
| ], | ||||||||||||
| sprintf('%s AND tvtpl.templateid=%s', $where, $resource['template']), | ||||||||||||
| $orderby | ||||||||||||
| ); | ||||||||||||
| while ($row = db()->getRow($rs)) { | ||||||||||||
| $result[] = $row; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ($idnames === '*') { | ||||||||||||
| $where = 'tv.id<>0'; | ||||||||||||
| } elseif (preg_match('@^[1-9][0-9]*$@', $idnames)) { | ||||||||||||
| $where = sprintf('tv.id=%s', $idnames); | ||||||||||||
| } elseif (strpos($idnames, "'") === 0) { | ||||||||||||
| $where = sprintf("tv.name IN (%s)", $idnames); | ||||||||||||
| return $result; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private function getResourceForTV($docid, $published) | ||||||||||||
| { | ||||||||||||
| if ($this->array_get($this->previewObject, 'template')) { | ||||||||||||
| $resource = $this->getDocument($docid, '*', null); | ||||||||||||
| $resource['template'] = $this->previewObject['template']; | ||||||||||||
| } elseif ($docid == $this->documentIdentifier) { | ||||||||||||
| $resource = $this->documentObject; | ||||||||||||
| } else { | ||||||||||||
| $where = sprintf("tv.name='%s'", db()->escape($idnames)); | ||||||||||||
| $resource = $this->getDocument($docid, '*', $published); | ||||||||||||
| } | ||||||||||||
| return $resource ?: false; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private function collectResourceFields($resource, $idnames) | ||||||||||||
| { | ||||||||||||
| $result = []; | ||||||||||||
| $rs = db()->select( | ||||||||||||
| $fields, | ||||||||||||
| [ | ||||||||||||
| '[+prefix+]site_tmplvars tv', | ||||||||||||
| 'INNER JOIN [+prefix+]site_tmplvar_templates tvtpl ON tvtpl.tmplvarid = tv.id', | ||||||||||||
| sprintf( | ||||||||||||
| "LEFT JOIN [+prefix+]site_tmplvar_contentvalues tvc ON tvc.tmplvarid=tv.id AND tvc.contentid='%s'", | ||||||||||||
| $docid | ||||||||||||
| ) | ||||||||||||
| ], | ||||||||||||
| sprintf('%s AND tvtpl.templateid=%s', $where, $resource['template']), | ||||||||||||
| $sort ? | ||||||||||||
| sprintf('%s %s', $this->join(',', explode(',', $sort), 'tv.'), $dir) | ||||||||||||
| : | ||||||||||||
| '' | ||||||||||||
| ); | ||||||||||||
| while ($row = db()->getRow($rs)) { | ||||||||||||
| $result[] = $row; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // get default/built-in template variables | ||||||||||||
| ksort($resource); | ||||||||||||
| foreach ($resource as $key => $value) { | ||||||||||||
| if ($idnames === '*' || in_array($key, explode(',', $idnames))) { | ||||||||||||
| if ($idnames === '*' || (is_string($idnames) && in_array($key, explode(',', $idnames)))) { | ||||||||||||
| $result[] = ['name' => $key, 'value' => $value]; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| return $result; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private function buildTVWhereClause($idnames) | ||||||||||||
| { | ||||||||||||
| if (is_array($idnames) && !empty($idnames)) { | ||||||||||||
| $escaped = implode("','", db()->escape($idnames)); | ||||||||||||
| return sprintf("tv.name IN ('%s')", $escaped); | ||||||||||||
| } | ||||||||||||
| if ($idnames === '*') { | ||||||||||||
| return 'tv.id<>0'; | ||||||||||||
| } | ||||||||||||
| if (preg_match('@^[1-9][0-9]*$@', $idnames)) { | ||||||||||||
| return sprintf('tv.id=%s', $idnames); | ||||||||||||
| } | ||||||||||||
|
||||||||||||
| } | |
| } | |
| if (is_string($idnames) && strlen($idnames) > 0 && $idnames[0] === "'") { | |
| return sprintf('tv.name IN (%s)', $idnames); | |
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$resultis now prefilled with built-in resource fields before the TV query runs, which reverses the previous ordering (TV rows first, then built-ins). This changes observable behavior for callers that iterategetTemplateVars('*', ...)and rely on$sortto control the leading records, because entries likealias/idnow appear before any sorted TV rows and can alter snippet/output logic that processes the list in order.Useful? React with 👍 / 👎.