Adding views

This commit is contained in:
Eric van der Vlist 2020-05-05 15:22:49 +02:00
parent 7d2b6e53b3
commit 0097514442
1 changed files with 52 additions and 7 deletions

View File

@ -76,8 +76,8 @@ if (!class_exists("Owark")) {
private $broken_links = array(); private $broken_links = array();
private $post_id = -1; private $post_id = -1;
private $post_type = ""; private $post_type = "";
private $version = '0.2'; private $version = '1.0';
private $db_version = '0.2'; private $db_version = '1.0';
private $notices = ""; private $notices = "";
/** /**
@ -149,14 +149,22 @@ if (!class_exists("Owark")) {
// Install or upgrade tables if needed // Install or upgrade tables if needed
$installed_ver = get_option( "owark_db_version" ); $installed_ver = get_option( "owark_db_version" );
$update_required = ($installed_ver != $this->db_version);
print_r_log("update_required: $update_required ($installed_ver vs {$this->db_version})");
global $wpdb; global $wpdb;
$table = $wpdb->prefix."owark"; $table = $wpdb->prefix."owark";
if ($installed_ver == '0.1') { if ($installed_ver == '0.1') {
// In version 0.1 final URLs where used but the broken link checkers update these URLs when a link is detected broken // In version 0.1 final URLs where used but the broken link checkers update these URLs when a link is detected broken
$table_links = $wpdb->prefix."blc_links"; // Let's replace these URLS by raw URLs...
$sql = "update $table as owark join $table_links as links on owark.url = links.final_url COLLATE latin1_swedish_ci set owark.url = links.url COLLATE latin1_swedish_ci"; $sql = "update
{$wpdb->prefix}owark as owark
join {$wpdb->prefix}blc_links as links on
owark.url = links.final_url COLLATE latin1_swedish_ci
join {$wpdb->prefix}blc_instances as instances on
instances.link_id = links.link_id set
owark.url = instances.raw_url ";
$wpdb->query($sql); $wpdb->query($sql);
$installed_ver = '0.2'; $installed_ver = '1.0';
update_option( "owark_db_version", $installed_ver ); update_option( "owark_db_version", $installed_ver );
} }
if ($installed_ver != $this->db_version) { if ($installed_ver != $this->db_version) {
@ -168,13 +176,50 @@ if (!class_exists("Owark")) {
arc_date datetime, arc_date datetime,
arc_location text, arc_location text,
encoding varchar(10), encoding varchar(10),
PRIMARY KEY(`id`), PRIMARY KEY (id),
KEY `url` (`url`(150)) )"; KEY url (`url`(150)) )";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql); dbDelta($sql);
update_option( "owark_db_version", $this->db_version ); update_option( "owark_db_version", $this->db_version );
}
if ($update_required) {
$sql = "CREATE OR REPLACE VIEW {$wpdb->prefix}owark_broken_links AS
SELECT
owark.id as id,
instances.raw_url as url,
instances.container_id as container_id,
instances.container_type as container_type,
instances.container_field as container_field
FROM
{$wpdb->prefix}owark as owark,
{$wpdb->prefix}blc_links as links,
{$wpdb->prefix}blc_instances AS instances
WHERE
owark.url = instances.raw_url
AND instances.link_id = links.link_id
AND broken = 1
AND last_check is not null
AND instances.link_id = links.link_id";
print_r_log("sql: $sql");
$wpdb->query($sql);
$sql = "CREATE OR REPLACE VIEW {$wpdb->prefix}owark_links_to_ckeck AS
SELECT
DISTINCT instances.raw_url as url
FROM
{$wpdb->prefix}blc_links as links,
{$wpdb->prefix}blc_instances AS instances
WHERE
instances.link_id = links.link_id
AND broken = 0
AND instances.link_id = links.link_id
AND url NOT IN (SELECT url FROM wp_owark)";
print_r_log("sql: $sql");
$wpdb->query($sql);
$this->notices = "<div class=\"updated fade\"><p><strong>The owark table has been installed or upgraded to version {$this->db_version}</strong></p></div>"; $this->notices = "<div class=\"updated fade\"><p><strong>The owark table has been installed or upgraded to version {$this->db_version}</strong></p></div>";
} }