From 688975f24fa50780e3dfff09afbdb0b25f2ac89d Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Sat, 9 Mar 2024 23:38:55 +0530 Subject: [PATCH] db-tabulator: allow putting sql in nowiki tags !web-restart --- .github/workflows/toolforge-deploy.yml | 2 +- db-tabulator/app.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/toolforge-deploy.yml b/.github/workflows/toolforge-deploy.yml index df4ce55..cc45c60 100644 --- a/.github/workflows/toolforge-deploy.yml +++ b/.github/workflows/toolforge-deploy.yml @@ -67,7 +67,7 @@ jobs: exit 1; fi; npm restart; - elif [[ "$(git diff --name-only HEAD HEAD@{1} | grep -c "web-endpoint")" -gt 0 || "$(git rev-list --format=%B --max-count=1 HEAD)" == *"!restart"* ]]; then + elif [[ "$(git diff --name-only HEAD HEAD@{1} | grep -c "web-endpoint")" -gt 0 || "$(git rev-list --format=%B --max-count=1 HEAD)" == *"!restart"* || "$(git rev-list --format=%B --max-count=1 HEAD)" == *"!web-restart"* ]]; then echo "Restarting SDZeroBot webservice ..."; cd /data/project/sdzerobot/www/js && npm restart; fi; diff --git a/db-tabulator/app.ts b/db-tabulator/app.ts index 78b3936..87ebbe1 100644 --- a/db-tabulator/app.ts +++ b/db-tabulator/app.ts @@ -151,14 +151,25 @@ export class Query { return this.template.getValue(param)?.replace(//g, '').trim(); } + getSql() { + let sql = this.getTemplateValue('sql'); + if (/^\s*/.test(sql)) { + return sql.replace(/^\s*/, '') + .replace(/<\/nowiki ?>\s*$/, ''); + } else { + // @deprecated + return sql + // Allow pipes to be written as {{!}} + ?.replace(/\{\{!\}\}/g, '|'); + } + } + // Errors in configs are reported to user through [[Module:Database report]] in Lua parseQuery() { this.config.interval = parseInt(this.getTemplateValue('interval')); // Use of semicolons for multiple statements will be flagged as error at query runtime - this.config.sql = this.getTemplateValue('sql') - // Allow pipes to be written as {{!}} - ?.replace(/\{\{!\}\}/g, '|'); + this.config.sql = this.getSql(); if (!this.config.sql) { this.isValid = false;