Update:
* Kalender Rechte sync Script Implementation
This commit is contained in:
Daniel Spitzer
2024-12-10 12:09:30 +01:00
parent 535ff886c6
commit b479f33bfe

View File

@@ -0,0 +1,109 @@
<?php
//require 'vendor/autoload.php';
require("../../config/config.php");
define('FRONKDB_SQLDEBUG', false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR . "/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR . "/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR . "/mvcfronk/mfBase/mfBaseController.php");
$me = new User(154);
define("INTERNAL_USER_ID", $me->id);
define("INTERNAL_USER_USERNAME", $me->username);
$calendar = CalendarModel::search(array("checkSubscriptions" => 1));
$adminUser = array(89, 173, 167, 8, 6, 9, 5,123);
foreach ($calendar as $cal) {
$allCalendar[$cal->go_calendar_id] = $cal->user_id;
}
foreach ($calendar as $cal) {
$update = 0;
$allCalendarUser = $allCalendar;
unset($newrights);
if (in_array($cal->user_id, $adminUser)) {
$admin = 1;
} else {
$admin = 0;
}
foreach ($allCalendarUser as $key => $value) {
if ($admin == 1 || $key == $cal->go_calendar_id) {
$newrights[$key] = "all";
} else {
$newrights[$key] = "read";
}
}
if (json_encode($newrights) != $cal->rights) {
$cal->update(array("rights" => json_encode($newrights)));
$update = 1;
}
if ($cal->colors) {
$stdColors = CalendarModel::$standardCalendarColors;
$colorsArray = json_decode($cal->colors, true);
$colors = $colorsArray;
foreach ($allCalendarUser as $key => $value) {
if ($colors[$key]) {
unset($colors[$key]);
} else {
$colorsArray[$key]['bgcolor'] = $stdColors[$key];
$colorsArray[$key]['txtcolor'] = "#000000";
}
}
if ($colors) {
foreach ($colors as $key => $value) {
if ($key != "998" && $key != "997") {
unset($colorsArray[$key]);
}
}
}
if (json_encode($colorsArray) != $cal->colors) {
$cal->update(array("colors" => json_encode($colorsArray)));
$update = 1;
}
}
if ($cal->groups) {
$groupArray = json_decode($cal->groups, true);
$groups = $groupArray;
foreach ($groups as $key => $value) {
foreach ($value["calendars"] as $key2 => $value2) {
if ((!$allCalendarUser[$value2['calendar_id']] && $value2['calendar_id'] != 997 && $value2['calendar_id'] != 998)) {
unset($groupArray[$key]["calendars"][$key2]);
} else {
unset($allCalendarUser[$value2['calendar_id']]);
}
}
}
if ($allCalendarUser) {
foreach ($groups as $key => $value) {
if ($value['name'] == "Persönlich") {
foreach ($allCalendarUser as $key2 => $value2) {
$groupArray[$key]["calendars"][] = array("calendar_id" => "$key2", "checked" => 0, "origin" => 1);
}
}
}
}
if (json_encode($groupArray, JSON_UNESCAPED_UNICODE) != $cal->groups) {
echo "groups";
$cal->update(array("groups" => json_encode($groupArray, JSON_UNESCAPED_UNICODE)));
$update = 1;
}
}
if ($update == 1) {
echo "save" . $cal->id . "\n";
$cal->save();
}
}