<?php
/**
 * File: class-installsingleplugin.php
 *
 *
 * @since 2024-08-12
 * @license GPL-3.0-or-later
 *
 * @package
 */

namespace Bdp\Modules\PluginInstaller\Controllers;

use Plugin_Upgrader;
use WP_Ajax_Upgrader_Skin;

class InstallSingleplugin
{
    public static function install_calendar ()
    {
        if ( isset( $_REQUEST[ 'install' ] ) ) {
            if ( !file_exists( dirname( BDP_LV_STARTUP_FILE ) . '/../kronos/kronos.php' ) ) {
                $pageName = 'Kalender';
                $page_exists = get_page_by_path( $pageName, OBJECT, 'page' );
                if ( is_object( $page_exists ) ) {
                    wp_delete_post( $page_exists->ID, false );
                }
                $calendar_connection = get_option( 'bdp_calendar_source_url',
                    'https://wiki.sachsen.pfadfinden.de/rest/calendar-services/1.0/calendar/export/subcalendar/private/ff69f5a689391ac0d7f78a70189cfde7c48cb923.ics' );
                if ( 'https://wiki.sachsen.pfadfinden.de/rest/calendar-services/1.0/calendar/export/subcalendar/private/ff69f5a689391ac0d7f78a70189cfde7c48cb923.ics' !== $calendar_connection ) {
                    update_option( 'kronos_calendar_url', $calendar_connection );
                }
                delete_option( 'bdp_calendar_source_url' );


                kompass_install_plugin( 'https://repos.contelli.de/plugins/kronos/download', 'kronos' );


            }
        } else {
            $install_link = admin_url( 'admin.php?page=kompass-calendar&install=true' );
            require dirname( __FILE__ ) . '/../views/install-item.php';
        }
    }

    public static function install_events ()
    {
        if ( isset( $_REQUEST[ 'install' ] ) ) {
            if ( !file_exists( dirname( BDP_LV_STARTUP_FILE ) . '/../solea/solea.php' ) ) {
                kompass_install_plugin( 'https://repos.contelli.de/plugins/solea/download', 'solea' );
            }
        } else {
            $install_link = admin_url( 'admin.php?page=kompass-events&install=true' );
            require dirname( __FILE__ ) . '/../views/install-item.php';
        }
    }
}