Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 796f6426 authored by Alexandre Roux's avatar Alexandre Roux
Browse files

unify methods

parent 31d34224
Loading
Loading
Loading
Loading
Loading
+18 −28
Original line number Diff line number Diff line
@@ -53,15 +53,11 @@ class BeforeCreateFilePlugin extends ServerPlugin {
	/**
	 * Assign a Nextcloud Talk room URL as the event location
	 *
	 * @param string $uri target file URI
	 * @param resource $data data
	 * @param INode $parent Sabre Node
	 * @param bool $modified modified
	 * @return
	 *
	 */

	public function beforeCreateFile($uri, &$data, INode $parent, &$modified) {
		$this->logger->debug('beforeCreateFile fired', ['app' => 'calendar', 'uri' => $uri]);
	public function checkAndProcessData(&$data) {
		if (is_resource($data)) {
			$data = stream_get_contents($data);
		}
@@ -70,15 +66,24 @@ class BeforeCreateFilePlugin extends ServerPlugin {
			$vCalendar = Reader::read($data);
		} catch (\Exception $e) {
			// The data is not a valid vCalendar object.
			$this->logger->debug('beforeCreateFile: payload is not valid vCalendar, skipping', [
				'app' => 'calendar',
				'uri' => $uri,
				'exception' => $e,
			]);
			return;
		}
		$this->processEventData($data, $vCalendar);
	}

	/**
	 * Assign a Nextcloud Talk room URL as the event location
	 *
	 * @param string $uri target file URI
	 * @param resource $data data
	 * @param INode $parent Sabre Node
	 * @param bool $modified modified
	 * @return
	 */

	public function beforeCreateFile($uri, &$data, INode $parent, &$modified) {
		$this->logger->debug('beforeCreateFile fired', ['app' => 'calendar', 'uri' => $uri]);
		$this->checkAndProcessData($data);
	}

	/**
@@ -93,22 +98,7 @@ class BeforeCreateFilePlugin extends ServerPlugin {

	public function beforeWriteContent($uri, INode $parent, &$data, &$modified) {
		$this->logger->debug('beforeWriteContent fired', ['app' => 'calendar', 'uri' => $uri]);
		if (is_resource($data)) {
			$data = stream_get_contents($data);
		}
		// Parse the data as a vCalendar object using Sabre\VObject.
		try {
			$vCalendar = Reader::read($data);
		} catch (\Exception $e) {
			// The data is not a valid vCalendar object.
			$this->logger->debug('beforeWriteContent: payload is not valid vCalendar, skipping', [
				'app' => 'calendar',
				'uri' => $uri,
				'exception' => $e,
			]);
			return;
		}
		$this->processEventData($data, $vCalendar);
		$this->checkAndProcessData($data);
	}

	/**