<?php


class schaden_activation{

    public function __construct()
    {
        $this->SA_message_table();
        $this->install_cronrunner();
        $this->reset_lock_bit();
    }

    public function SA_message_table() {

        global $wpdb;
        $table_name = $wpdb->prefix . 'akte';
        $charset_collate = $wpdb->get_charset_collate();

        $sql = "CREATE TABLE $table_name (
		id mediumint(9) NOT NULL AUTO_INCREMENT,
		postid mediumint(9) NOT NULL,
		nachricht text NOT NULL,
		anhang text NOT NULL,
		eintrag TIMESTAMP DEFAULT 0,
		UNIQUE KEY id (id)
	) $charset_collate;";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

        dbDelta( $sql );
    }

    function install_cronrunner() {
        if (! wp_next_scheduled ( 'SA_cron_runner' )) {
            wp_schedule_event( time(), '1min', 'SA_cron_runner');
        }
    }

    public function reset_lock_bit()
    {
        update_option('SA_lock_bit', false, false );
    }

}