Skip to content

Commit

Permalink
Merge pull request #939 from ByteHamster/fix-user-deletion
Browse files Browse the repository at this point in the history
Fixed user deletion
  • Loading branch information
ByteHamster authored Jun 12, 2020
2 parents 91f46e7 + fbd160b commit fd05722
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Core/Frameworks/Baikal/Model/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,17 @@ function hasInstances() {
}

function destroy() {
if (!$this->hasInstances()) {
$hasInstances = $this->hasInstances();
if (!$hasInstances) {
$oEvents = $this->getEventsBaseRequester()->execute();
foreach ($oEvents as $event) {
$event->destroy();
}
}

parent::destroy();
$this->oCalendar->destroy();
if (!$hasInstances) {
$this->oCalendar->destroy();
}
}
}
7 changes: 4 additions & 3 deletions Core/Frameworks/Baikal/Model/Calendar/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function hasInstances() {
$rSql = $GLOBALS["DB"]->exec_SELECTquery(
"count(*)",
"calendarinstances",
"calendarid" . "='" . $this->aData["calendarid"] . "'"
"calendarid" . "='" . $this->aData["id"] . "'"
);

if (($aRs = $rSql->fetch()) === false) {
Expand All @@ -53,8 +53,9 @@ function hasInstances() {
}

function destroy() {
if (!$this->hasInstances()) {
parent::destroy();
if ($this->hasInstances()) {
throw new \Exception("Trying to destroy a calendar with instances");
}
parent::destroy();
}
}
4 changes: 3 additions & 1 deletion Core/Frameworks/Baikal/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ function destroy() {
# TODO: delete all related resources (principals, calendars, calendar events, contact books and contacts)

# Destroying identity principal
$this->oIdentityPrincipal->destroy();
if ($this->oIdentityPrincipal != null) {
$this->oIdentityPrincipal->destroy();
}

$oCalendars = $this->getCalendarsBaseRequester()->execute();
foreach ($oCalendars as $calendar) {
Expand Down
1 change: 1 addition & 0 deletions Core/Frameworks/BaikalAdmin/Controller/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ protected function actionDelete() {
$oUser->destroy();
} catch (\Exception $e) {
# user is already deleted; silently discarding
error_log($e);
}

# Redirecting to admin home
Expand Down

0 comments on commit fd05722

Please sign in to comment.