#!/bin/sh
# Thinkera Academy — apply the rebrand. Safe to re-run (after installing a plugin, run it again).
#   ./rebrand.sh     (from platform/moodle)
set -e
cfg() { docker compose exec -u www-data -T moodle php admin/cli/cfg.php "$@" >/dev/null && echo "  $*"; }
php() { docker compose exec -u www-data -T moodle php "$@"; }

echo "theme"
cfg --name=theme --set=thinkera
cfg --name=allowuserthemes --set=0
cfg --name=allowcoursethemes --set=0
cfg --name=allowcategorythemes --set=0
cfg --name=allowthemechangeonurl --set=0

echo "links that lead back to the product's own sites"
cfg --name=docroot --set=""                         # no "Documentation for this page"
cfg --name=showservicesandsupportcontent --set=0    # no "Services and support"
cfg --name=enableuserfeedback --set=0               # no "Give feedback about this software"
cfg --name=enablesharingtomoodlenet --set=0         # no share-to-MoodleNet
cfg --component=tool_mobile --name=setuplink --set=""       # no "Get the mobile app"
cfg --component=tool_dataprivacy --name=showdataretentionsummary --set=0

echo "Arabic by default (users can still switch in the language menu)"
cfg --name=lang --set=ar
cfg --name=autolang --set=0
php -r 'define("CLI_SCRIPT", true); require("/var/www/html/config.php");
  $DB->set_field_select("user", "lang", "ar", "deleted = 0 AND lang <> ?", ["ar"]);
  echo "  every account set to Arabic
";'

echo "site name"
php -r 'define("CLI_SCRIPT", true); require("/var/www/html/config.php");
  $DB->set_field("course", "fullname", "أكاديمية Thinkera", ["id" => SITEID]);
  $DB->set_field("course", "shortname", "Thinkera", ["id" => SITEID]);
  echo "  site: أكاديمية Thinkera / Thinkera\n";'

echo "sign-up, Google sign-in and the course catalogue"
php public/local/thinkera/cli/setup_auth.php
cfg --name=custommenuitems --set="الدورات|/local/thinkera/catalogue.php"
cfg --name=frontpageloggedin --set=""

echo "outgoing email (SMTP_* in .env)"
php public/local/thinkera/cli/set_mail.php
php public/local/thinkera/cli/set_bbb.php
php public/local/thinkera/cli/set_whatsapp.php

echo "Google Analytics (GANALYTICSCODE in .env)"
php public/local/thinkera/cli/set_analytics.php

echo "every interface string"
php public/theme/thinkera/cli/rebrand_strings.php

echo "caches"
php admin/cli/purge_caches.php
echo "done"
