<?php
/*
 * Copyright (c) 2017-2024 Aimy Extensions, Netzum Sorglos Software GmbH
 * Copyright (c) 2015-2017 Aimy Extensions, Lingua-Systems Software GmbH
 *
 * https://www.aimy-extensions.com/
 *
 * License: GNU GPLv2, see LICENSE.txt within distribution and/or
 *          http://www.aimy-extensions.com/software-license.html
 */
 defined( '_JEXEC' ) or die(); use Joomla\CMS\Factory; abstract class AimyIndexNowUpdateServer { static public function cleanup_server_list( &$adapter ) { $class = get_class( $adapter ); $element = 'aimyindexnow'; if ( strpos( $class, 'Component' ) ) { $element = 'com_' . $element; } elseif ( strpos( $class, 'Module' ) ) { $element = 'mod_' . $element; } $eid = self::get_extension_id( $element ); if ( empty( $eid ) ) { throw new RuntimeException( 'Could not determine element id' ); } return self::cleanup_servers( $eid, 'aimyindexnow.xml' ); } static private function cleanup_servers( $eid, $url_suffix ) { $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( 's.update_site_id' ) ) ->from( $db->quoteName( '#__update_sites_extensions', 'e' ) ) ->join( 'INNER', $db->quoteName( '#__update_sites', 's' ) . ' ON ' . $db->quoteName( 'e.update_site_id' ) . ' = ' . $db->quoteName( 's.update_site_id' ) ) ->where( $db->quoteName( 'e.extension_id' ) . ' = ' . $db->quote( $eid ) . ' AND ' . $db->quoteName( 's.location' ) . ' LIKE ' . $db->quote( '%' . $url_suffix ) ); $db->setQuery( $q ); $sites = $db->loadObjectList(); foreach ( $sites as $site ) { try { $db->transactionStart(); $q = $db->getQuery( true ); $q->delete( $db->quoteName( '#__update_sites' ) ) ->where( $db->quoteName( 'update_site_id' ) . ' = ' . $db->quote( $site->update_site_id ) ); $db->setQuery( $q ); $db->execute(); $q = $db->getQuery( true ); $q->delete( $db->quoteName( '#__update_sites_extensions' ) ) ->where( $db->quoteName( 'update_site_id' ) . ' = ' . $db->quote( $site->update_site_id ) ); $db->setQuery( $q ); $db->execute(); $db->transactionCommit(); } catch ( Exception $e ) { $db->transactionRollback(); throw new Exception( $e->getMessage() ); } } } static private function get_extension_id( $elem ) { $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( 'extension_id' ) ) ->from( $db->quoteName( '#__extensions' ) ) ->where( $db->quoteName( 'element' ) . ' = ' . $db->quote( $elem ) ); $db->setQuery( $q ); $d = $db->loadObject(); if ( is_object( $d ) and isset( $d->extension_id ) ) { return $d->extension_id; } return null; } } 
