diff check_sections.php @ 1:1f9d2bfe1d13

handle new section created by user, update sections_index table
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 19 Mar 2015 18:36:21 +0100
parents 723a162b6627
children 373c8ecad8b4
line wrap: on
line diff
--- a/check_sections.php	Thu Mar 19 15:06:34 2015 +0100
+++ b/check_sections.php	Thu Mar 19 18:36:21 2015 +0100
@@ -56,20 +56,33 @@
 }
 
 function checkSections($count){
-
-/*	$query="SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
+	/*
+	$query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
 		FROM sections
 		JOIN books ON sections.books_id = books.id
 		WHERE NOT EXISTS
 		(SELECT 1 FROM sections_versions WHERE books_id=sections.books_id)
 		GROUP BY books_id, start_page, end_page
-		HAVING COUNT( * ) >=".$count."
-		ORDER BY COUNT( * ) DESC ";*/
+		HAVING COUNT( * ) >=".$count.")
+		UNION
+		(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections_revisions.name, start_page, end_page, COUNT( * ) AS count 
+                FROM sections_revisions
+                JOIN books ON sections_revisions.books_id = books.id
+		JOIN (
+			SELECT sections_versions.id 
+			FROM sections_versions WHERE sections_versions.version=(SELECT MAX(version) FROM sections_versions) 
+			GROUP BY books_id
+		) AS t ON t.id=sections_revisions.versions_id
+		WHERE deleted=0 
+                GROUP BY books_id, versions_id,start_page, end_page
+                HAVING COUNT( * ) >=".$count.")
+		ORDER BY count DESC ";
+		*/
 	$query="(SELECT books.name AS book_name, books.level1, books.level2, books.period, books.id, sections.name, start_page, end_page, COUNT( * ) AS count
-		FROM sections
-		JOIN books ON sections.books_id = books.id
+		FROM sections_index
+		JOIN books ON sections_index.books_id = books.id
 		WHERE NOT EXISTS
-		(SELECT 1 FROM sections_versions WHERE books_id=sections.books_id)
+		(SELECT 1 FROM sections_versions WHERE books_id=sections_index.books_id)
 		GROUP BY books_id, start_page, end_page
 		HAVING COUNT( * ) >=".$count.")
 		UNION