[Java hand-in-hand tutorial][second season] Java backend blog system article system – No5

After a month off, we started updating again. The specific reason can only be that there are too many things during the New Year, I do not know how to work hard when I am young, but when I grow up, EVERYTHING is tied to me.

This installment focuses on analyzing the programming of WordPress by observing the database based on the effect of WordPress execution.

Github address: github.com/pc859107393…

I Jane books home page is: www.jianshu.com/users/86b79…

Last issue was: [Hand-in-hand tutorial][second season] Java backend blogging system article system – No4

Walking Java full stack

tool

  • An IDE for idea16
  • The JDK environment is 1.8
  • Gradle build, version: 2.14.1
  • The Mysql version is 5.5.27
  • Tomcat version 7.0.52
  • Flowchart Drawing (XMIND)
  • Modeling analysis software PowerDesigner16.5
  • Database tool MySQLWorkBench, version 6.3.7build

The current target

  • Conduct programming analysis according to WordPress work
  • Complete the process analysis of article saving and draft saving

Analyze program design based on WordPress article save and draft save

First, we opened WordPress, logged in to the console and saved the draft and articles randomly. Then we exported the posts table in the database and added the following contents:

{
"RECORDS":[
{
"ID":"329"."post_author":"1"."post_date":"The 02-16-2017 09:57:29"."post_date_gmt":"The 02-16-2017 01:57:29"."post_title":"No4: The Java Backend Blog system -- No4"."post_excerpt":""."post_status":"inherit"."comment_status":"closed"."comment_count":"0"."ping_status":"closed"."post_password":""."post_name":"328-revision-v1"."to_ping":""."pinged":""."post_modified":"The 02-16-2017 09:57:29"."post_modified_gmt":"The 02-16-2017 01:57:29"."post_content_filtered":""."post_parent":"328"."guid":"http://acheng1314.cn/?p=329"."menu_order":"0"."post_type":"revision"."post_mime_type":""."comment_count(2)":"0"
},
{
"ID":"328"."post_author":"1"."post_date":"The 02-16-2017 09:58:19"."post_date_gmt":"The 02-16-2017 01:58:19"."post_title":"No4: The Java Backend Blog system -- No4"."post_excerpt":""."post_status":"publish"."comment_status":"open"."comment_count":"0"."ping_status":"open"."post_password":""."post_name":"java-%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e7%a8%8b%e7%ac%ac%e4%ba%8c%e5%ad%a3java-%e5%90%8e%e7%ab%af%e5%8d%9a%e5%ae%a2% e7%b3%bb%e7%bb%9f%e6%96%87%e7%ab%a0%e7%b3%bb%e7%bb%9f-no4"."to_ping":""."pinged":""."post_modified":"The 02-16-2017 09:58:19"."post_modified_gmt":"The 02-16-2017 01:58:19"."post_content_filtered":""."post_parent":"0"."guid":"http://acheng1314.cn/?p=328"."menu_order":"0"."post_type":"post"."post_mime_type":""."comment_count(2)":"0"
},
{
"ID":"327"."post_author":"1"."post_date":"The 02-14-2017 23:20:15"."post_date_gmt":"The 02-14-2017 15:20:15"."post_title":"My draft."."post_excerpt":""."post_status":"inherit"."comment_status":"closed"."comment_count":"0"."ping_status":"closed"."post_password":""."post_name":"323-revision-v1"."to_ping":""."pinged":""."post_modified":"The 02-14-2017 23:20:15"."post_modified_gmt":"The 02-14-2017 15:20:15"."post_content_filtered":""."post_parent":"323"."guid":"http://acheng1314.cn/?p=327"."menu_order":"0"."post_type":"revision"."post_mime_type":""."comment_count(2)":"0"
},
{
"ID":"326"."post_author":"1"."post_date":"The 02-14-2017 23:20:01"."post_date_gmt":"The 02-14-2017 15:20:01"."post_title":""."post_excerpt":""."post_status":"inherit"."comment_status":"closed"."comment_count":"0"."ping_status":"closed"."post_password":""."post_name":"323-revision-v1"."to_ping":""."pinged":""."post_modified":"The 02-14-2017 23:20:01"."post_modified_gmt":"The 02-14-2017 15:20:01"."post_content_filtered":""."post_parent":"323"."guid":"http://acheng1314.cn/?p=326"."menu_order":"0"."post_type":"revision"."post_mime_type":""."comment_count(2)":"0"
},
{
"ID":"325"."post_author":"1"."post_date":"The 02-10-2017 22:34:41"."post_date_gmt":00-00-00 00:00:00 ""."post_title":"Automatic draft"."post_excerpt":""."post_status":"auto-draft"."comment_status":"open"."comment_count":"0"."ping_status":"open"."post_password":""."post_name":""."to_ping":""."pinged":""."post_modified":"The 02-10-2017 22:34:41"."post_modified_gmt":00-00-00 00:00:00 ""."post_content_filtered":""."post_parent":"0"."guid":"http://acheng1314.cn/?p=325"."menu_order":"0"."post_type":"post"."post_mime_type":""."comment_count(2)":"0"
},
{
"ID":"323"."post_author":"1"."post_date":"The 02-14-2017 23:20:15"."post_date_gmt":00-00-00 00:00:00 ""."post_title":"My draft."."post_excerpt":""."post_status":"draft"."comment_status":"open"."comment_count":"0"."ping_status":"open"."post_password":""."post_name":""."to_ping":""."pinged":""."post_modified":"The 02-14-2017 23:20:15"."post_modified_gmt":"The 02-14-2017 15:20:15"."post_content_filtered":""."post_parent":"0"."guid":"http://acheng1314.cn/?p=323"."menu_order":"0"."post_type":"post"."post_mime_type":""."comment_count(2)":"0"}}]Copy the code

In the above data, we have deleted the data of the article content (the amount of data is too large to be convenient to refer to). Then we carefully analyze the JSON data above, and we can draw the following conclusions:

  1. Article:
    • The ids 329 and 328 represent the same article (published immediately after editing).
    • The different fields are:
      • ID
      • post_date
      • post_date_gmt
      • post_status
      • comment_status
      • ping_status
      • post_name
      • post_modified
      • post_modified_gmt
      • post_parent
      • post_type

Through the above comparison, we can come to the following conclusion:

  • After the article is edited and published, there is a record of the initial version and a record of the official release.
  • The main differences between published articles and article history are as follows:
-- -- -- - > the official launch "post_status" : "publish", "comment_status" : "open", "ping_status" : "open", "post_name":"java-%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e7%a8%8b%e7%ac%ac%e4%ba%8c%e5%ad%a3java-%e5%90%8e%e7%ab%af%e5%8d% 9a%e5%ae%a2%e7%b3%bb%e7%bb%9f%e6%96%87%e7%ab%a0%e7%b3%bb%e7%bb%9f-no4", "post_type":"post", "post_parent":"0", ----> Historical record "post_status":"inherit", "comment_status":"closed", "ping_status":"closed", "post_name":" 328-Revision-v1 ", "post_type":"revision", "post_parent":"328",Copy the code
  1. Draft:

    • The ids 323, 325, 326 and 327 are all drafts and the same draft.
    • The specific differences are similar to those above, so we can sort them out by ourselves.
  2. Summary:

  • Both articles and drafts are fully documented.
  • The format of the essay is similar to that of the draft.
  • Drafts are divided into automatic drafts and manual drafts.
  • The version record is also a complete record, except for some key field changes.

The article groups correlation analysis

SELECT
  `ID`.`post_title`.`post_date`.`post_content`
FROM
  `wp_posts`
WHERE
  `post_type` = 'post'
  AND
  `post_status` = 'publish'
ORDER BY
  `ID`Copy the code

The above statement can find out the public article, article ID at a glance.

At the same time, by observing the database, we can conclude that the database related to article classification is as follows:

  • wp_terms
  • wp_term_taxonomy
  • wp_term_relationships

But so many tables are related to the article classification, then the article classification is divided into what? Given the large amount of data supported by the simple architecture of WordPress, it’s a safe bet that article tags and category categories go together. So let’s look at the basic wp_terms first.

term_id name slug term_group
1 java web java-web 0
2 C Language Learning how2use_c 0
3 Android development makeandroid 0
4 Comprehensive summary all_log 0
5 Personal life myself_life 0
6 post-format-aside post-format-aside 0
7 reprinted from_others 0
8 Android Coder android-coder 0
9 link %e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5 0
10 JavaWeb javaweb 0
11 java web java-web 0
12 Spring spring 0
13 Mybatis mybatis 0
14 Java back-end java%e5%90%8e%e7%ab%af 0
15 JavaWeb javaweb 0
16 The MySQL database mysql%e6%95%b0%e6%8d%ae%e5%ba%93 0
17 The whole stack tutorial %e5%85%a8%e6%a0%88%e6%95%99%e7%a8%8b 0
18 java java 0

The above table is the WP_TERM table on my online server. Maybe we don’t know what it means for the moment, but it’s ok. Let’s move on to wP_term_taxonomy.

term_taxonomy_id term_id taxonomy description parent count
1 1 category 0 17
2 2 category 0 0
3 3 category 0 20
4 4 category 0 6
5 5 category 0 1
6 6 post_format 0 44
7 7 category 0 8
8 8 link_category 0 2
9 9 nav_menu 0 0
10 10 link_category 0 0
11 11 post_tag 0 2
12 12 post_tag 0 4
13 13 post_tag 0 4
14 14 post_tag 0 3
15 15 post_tag 0 2
16 16 post_tag 0 3
17 17 post_tag 0 3
18 18 post_tag 0 1

Through the above table we can understand the name corresponding to term_id are used respectively, they have article groups, article tags, link tags and so on.

But there’s nothing to classify the above articles, so let’s move on to what’s inside the WP_TERM_relationships table.

object_id term_taxonomy_id term_order
1 8 0
2 8 0
9 4 0
9 6 0
11 4 0
11 6 0
16 3 0
16 6 0

There’s a lot of data in the table that’s omitted here.

The name object_id in the table above implies the ID of the object, indicating that it is not only the article but also other categorical information.

Let’s take a look at our wP_posts table, which briefly reads as follows:

ID post_title post_date post_content
9 List of IT product documents The 2015-09-22 16:44:48 Content omitted
11 At the beginning of the site, everything from scratch, the site is built with wordpress, based on PHP. The 2015-09-22 16:45:32

In fact, we don’t need that much data, we just need to throw data and simple comparison can know the result.

  • The term_taxonomy_id of articles 9 and 11 is 4, 6, 4, 6, respectively
  • Taxonomy = 4 and taxonomy = 6
term_id taxonomy
category post_format
  • Finally, we can see in wp_terms that term_id is 4 and term_id is 6
term_id name slug term_group
4 Comprehensive summary all_log 0
6 post-format-aside post-format-aside 0

So finally, we can understand the general search structure of classified information through this, and the general search of the article classification is as follows:

Article ID “term_taxonomy_id” in “wp_term_relationships” : “Term_taxonomy_id” in “wp_term_relationships” : yes Finally, the specific name can be found in the WP_TERM table based on term_id.

At this point the classification information basic search is completed.

conclusion

  1. The essay and draft are just a few key information differences
  2. Both articles and drafts have a complete history
  3. Article categories are in the article relation table
  4. The article relational table contains article contents, article labels, and so on
  5. The rest of the article properties can be seen by executing them on WordPress and then looking backwards at the database