Merge branch 'matrix-backend' into experimental

# Conflicts:
#	lib/Controller/TicketController.php
This commit is contained in:
Ben 2021-09-18 10:47:51 +02:00
commit 332497ea74
Signed by: ben
GPG key ID: 0F54A7ED232D3319
6 changed files with 859 additions and 136 deletions

View file

@ -2,13 +2,15 @@
"name": "upschooling/upschooling",
"description": "UPschooling Support Platform",
"type": "project",
"license": "AGPL",
"license": "AGPL-3.0-or-later",
"authors": [
{
"name": "UPschooling"
}
],
"require": {},
"require": {
"aryess/php-matrix-sdk": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"nextcloud/coding-standard": "^0.5.0"
@ -25,4 +27,4 @@
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix"
}
}
}

840
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -3,11 +3,25 @@
namespace OCA\UPschooling\AppInfo;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
class Application extends App {
class Application extends App implements IBootstrap {
public const APP_ID = 'upschooling';
public function __construct() {
parent::__construct(self::APP_ID);
}
public function register(IRegistrationContext $context): void
{
// Register the composer autoloader for packages shipped by this app, if applicable
include_once __DIR__ . '/../../vendor/autoload.php';
}
public function boot(IBootContext $context): void
{
// nothing to boot?
}
}

View file

@ -3,15 +3,20 @@
namespace OCA\UPschooling\Controller;
use OCA\UPschooling\AppInfo\Application;
use OCA\UPschooling\Service\MatrixService;
use OCA\UPschooling\Service\TicketService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
class TicketController extends Controller {
/** @var TicketService */
private $service;
/** @var MatrixService */
private $matrix;
/** @var string */
private $userId;
@ -19,9 +24,11 @@ class TicketController extends Controller {
public function __construct(IRequest $request,
TicketService $service,
MatrixService $matrix,
$userId) {
parent::__construct(Application::APP_ID, $request);
$this->service = $service;
$this->matrix = $matrix;
$this->userId = $userId;
}

View file

@ -0,0 +1,65 @@
<?php
namespace OCA\UPschooling\Service;
use Aryess\PhpMatrixSdk\Exceptions\MatrixRequestException;
use \Psr\Log\LoggerInterface;
use Aryess\PhpMatrixSdk\Exceptions\MatrixException;
use Aryess\PhpMatrixSdk\MatrixClient;
use Aryess\PhpMatrixSdk\Room;
class MatrixService
{
/** @var LoggerInterface */
private $logger;
/** @var string */
private $channel;
/** @var MatrixClient */
private $client;
/** @var string */
private $token;
/** @var Room */
private $room;
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
$this->channel = "#issue:synapse";
$this->client = new MatrixClient("http://synapse:8008");
$this->token = $this->client->login("upschooling", "secret");
try {
$this->room = $this->client->createRoom($this->channel, false, array());
} catch (MatrixException $e) {
$this->logger->error("Could not create room ".$this->channel, array('exception' => $e));
}
}
/**
* Sets a property on a channel.
*
* @param string $eventType a unique property identifier with reverse domain notation, e.g. com.example.property.
* @param array $content the contents as a JSON serializable array.
* @throws MatrixException
*/
public function setProperty(string $eventType, array $content)
{
$this->room->sendStateEvent($eventType, $content);
}
/**
* @param string $eventType a unique property identifier with reverse domain notation, e.g. com.example.property.
* @return array the contents of the room state.
* @throws MatrixException|MatrixRequestException
*/
public function getProperty(string $eventType): array
{
// first parameter should be $this->room->roomId
return $this->client->api()->getStateEvent($this->channel, $eventType);
}
}

View file

@ -5,10 +5,67 @@ IFS=$'\n\t'
DIR="${0%/*}"
podman run -d --name=nextcloud --replace=true -p 8080:80 -v "$DIR:/var/www/html/custom_apps/upschooling" docker.io/nextcloud
# replace containers
podman rm -if synapse
podman rm -if nextcloud
podman run -d --name=nextcloud -p 8080:80 -v "$DIR:/var/www/html/custom_apps/upschooling" docker.io/nextcloud
podman exec nextcloud chown -R 33 /var/www/html/custom_apps
"$DIR/podman-reown.sh"
podman exec --user 33 nextcloud bash -c 'cd /var/www/html/custom_apps/upschooling && make composer'
podman exec --user 33 nextcloud php occ maintenance:install --database sqlite --admin-user admin --admin-pass admin
podman exec --user 33 nextcloud php occ config:system:set --value=true --type=boolean debug
podman exec --user 33 nextcloud php occ app:enable --force upschooling
if podman volume exists synapse-data; then
echo "Found existing synapse-data volume"
else
podman run --rm \
--name=synapse \
--hostname synapse \
"--mount=type=volume,src=synapse-data,dst=/data" \
-e SYNAPSE_SERVER_NAME=synapse \
-e SYNAPSE_REPORT_STATS=no \
docker.io/matrixdotorg/synapse \
generate
echo "Generated fresh synapse-data volume"
fi
podman run -d \
--name=synapse \
"--mount=type=volume,src=synapse-data,dst=/data" \
"--network=container:$(podman inspect --format "{{.Id}}" nextcloud)" \
--hostname synapse \
docker.io/matrixdotorg/synapse
# wait for synapse to start
MAX_TRIES=15
for ((i = 0 ; i < $MAX_TRIES ; i++)); do
if podman logs synapse 2>&1 | grep -q "Synapse now listening on TCP port 8008"; then
echo -e "Synapse has started. \e[1;38;5;2mOK\033[0m"
break
fi
sleep 1
done
if [[ $i -ge $MAX_TRIES ]]; then
echo "Synapse did not start in time! Use \`podman logs synapse\` to investigate"
exit 1
fi
set +e
REGISTER_USER_OUTPUT="$(podman exec synapse register_new_matrix_user -u upschooling -p secret -a -c /data/homeserver.yaml http://localhost:8008)"
REGISTER_USER_SUCCESS=$?
set -e
if [[ "$REGISTER_USER_SUCCESS" != "0" ]]; then
if echo $REGISTER_USER_OUTPUT | grep -q "User ID already taken."; then
echo -e "User @upschooling:synapse already exists. \e[1;38;5;2mOK\033[0m"
else
echo "Could not create user @upschooling:synapse"
echo $REGISTER_USER_OUTPUT
exit 1
fi
else
echo -e "Matrix user @upschooling:synapse created. \e[1;38;5;2mOK\033[0m"
fi