Updated DB System from post status

This commit is contained in:
Cyrille L 2022-03-05 18:06:48 +01:00
parent e45aee1e25
commit 1786ceb222
4 changed files with 113 additions and 52 deletions

View File

@ -9,13 +9,15 @@
# Get Post Hash & Status From Database
#======================================================================
gsl__db_get_post_datas() {
gsl_db_post_hash=0
if [[ -f "$gsl_file_db_post" ]];then
gsl_db_post_hash=`
awk -F: 'NR == 1 {print $3}' \
"$gsl_file_db_post"`
! [[ "$gsl_db_post_hash" ]] \
&& gsl_db_post_hash=0
gsl_db_post_status=`
awk -F: 'NR == 2 {print $2}' \
"$gsl_file_db_post"`
@ -27,37 +29,68 @@ fi
# Get Post Hash and Compare from Database
#======================================================================
gsl__db_compare_post_hash() {
! (( $gsl_post_hash == $gsl_db_post_hash )) \
&& gsl__logs_print \
gsl_checker_war=true
if ! (( $gsl_post_hash == $gsl_db_post_hash ));then
gsl__logs_print \
"$gsl_log_w" \
"Post" \
"Hash" \
"$gsl_post Changed ($gsl_post_hash)" \
"${PWD}/$gsl_post" \
&& gsl_checker_war=true \
&& return
"${PWD}/$gsl_post"
gsl_post_new_hash=true
else
gsl__logs_print \
"$gsl_log_w" \
"Post" \
"Hash" \
"$gsl_post already checked" \
"${PWD}/$gsl_post"
fi
}
#======================================================================
# Set Post Status in Database according to proceess
#======================================================================
gsl__db_set_post_status() {
echo "D> DB:$gsl_file_db_post $gsl_process > $gsl_db_post_status"
case "$gsl_process" in
Checked)
chk)
case "$gsl_db_post_status" in
Checked)
gsl__db_compare_post_hash || return # Do Nothing if same Hash
chk)
gsl__db_compare_post_hash
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
gsl__db_create_post
;;
Made)
return
;;
Online)
return
;;
*)
wip)
gsl__db_compare_post_hash
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
gsl_process="wip"
gsl__db_create_post
;;
www)
gsl__db_compare_post_hash
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
gsl_process="www"
gsl__db_create_post
;;
""|=)
echo "D> Create..."
gsl__db_create_post
;;
esac
;;
wip)
case "$gsl_db_post_status" in
chk)
sed -i "2s/.*/Status:$gsl_process/" "$gsl_file_db_post" && \
gsl__logs_print \
"$gsl_log_w" \
"DB" \
"Post" \
"Status:$gsl_process ; $gsl_post" \
"$gsl_file_db_post"
gsl_checker_war=true
;;
esac
;;
esac
@ -67,6 +100,7 @@ esac
# Create DB File from Data Post
#======================================================================
gsl__db_create_post() {
echo "D> DB: $gsl_process > $gsl_db_post_status > $gsl_checker_err"
if [[ "$gsl_checker_err" ]];then
[[ -f "$gsl_file_db_post" ]] \
&& rm -f "$gsl_file_db_post" \
@ -81,6 +115,11 @@ fi
touch "$gsl_file_db_post"
# Check webserver files
gsl__page_prepare_datas
[[ -f $gsl_srv_wip_page ]] \
&& gsl_process=wip
# Main Print
printf '%s\n%s\n%s\n' \
"Post:${PWD}/$gsl_post:$gsl_post_hash:$gsl_post_size" \

View File

@ -21,21 +21,37 @@ gsl__page_create
cat -n "$gsl_srv_wip_page"
}
#======================================================================
# Sync Files from Templates to webserver
#======================================================================
gsl__srv_sync() {
# Sync Files and Folders
for folder in `find $gsl_this_conf_domain/* -type d`
do
rsync -a "$folder" "$gsl_srv_wip" && \
gsl__logs_print \
"$gsl_log_w" \
"Server" \
"Sync" \
"$folder" \
"$gsl_srv_wip"
done
}
#----------------------------------------------------------------------
# Get Datas for Post/Page
#----------------------------------------------------------------------
gsl__page_prepare_datas() {
echo "D> $gsl_this_conf_domain"
# Source config website (DATAS)
source "$gsl_this_conf_domain/$gsl_find_domain.conf"
# Get Needed Headers DATAS
gsl__get_needed_headers
# Check for Files & Folders in server
gsl_srv_wip="$gsl_site_server/$gsl_site_ndd/wip"
mkdir -p "$gsl_srv_wip"
# Sync Files and Folders
for folder in `find $gsl_this_conf_domain/* -type d`
do
rsync -a "$folder" "$gsl_srv_wip"
done
# Post or Page
case "$gsl_post_type" in
@ -59,7 +75,7 @@ gsl_uri_site_logo="$gsl_uri/templates/$gsl_site_logo"
#----------------------------------------------------------------------
gsl__check_srv_files() {
if [[ -f "$1" ]];then
echo "! Replaced Page: $1"
echo "! Replace Page: $1"
fi
}
@ -68,23 +84,31 @@ fi
#======================================================================
gsl__page_create_listing() {
# Check if Post is in list ; Status Made
[[ "$gsl_db_post_status" == "Made" ]] \
&& gsl__logs_print \
"$gsl_log_i" \
"Post" \
"Make" \
"$gsl_post already added to Latest listings" \
"$gsl_file_db_posts" \
&& return
case "$gsl_db_post_status" in
wip|www)
gsl__logs_print \
"$gsl_log_i" \
"Post" \
"Make" \
"$gsl_post already added to Latest listings" \
"$gsl_file_db_posts"
return
;;
esac
touch "$gsl_dir_domain_tpl/last-posts-list.html"
gsl_max_posts_list=5
gsl_cur_posts_list=`cat "$gsl_dir_domain_tpl/last-posts-list.html" | wc -l`
if (( $((gsl_cur_posts_list )) >= 25 ));then
echo "D> $gsl_cur_posts_list * $gsl_max_posts_list"
for i in `seq 1 5`;
gsl_list_max_posts=5
gsl_list_lines_per_post=5
gsl_list_max_lines=$(( gsl_list_max_posts * gsl_list_lines_per_post))
gsl_list_cur_lines=`
cat "$gsl_dir_domain_tpl/last-posts-list.html" \
| wc -l`
if (( $((gsl_list_cur_lines )) >= $gsl_list_max_lines ));then
echo "D> $gsl_list_cur_lines > $gsl_list_max_lines"
for i in `seq 1 $gsl_list_lines_per_post`
do
sed -i "1d" "$gsl_dir_domain_tpl/last-posts-list.html"
done

View File

@ -15,8 +15,13 @@
#=======================================================================
gsl__all_makers() {
unset gsl_check_done
# Code readability a11y
gsl_a11y_post=`mktemp`
gsl__prepare_makers
gsl__page_prepare_datas
mkdir -p "$gsl_srv_wip"
gsl__srv_sync
# Create Listng Page
gsl__page_create_listing
@ -76,18 +81,9 @@ grep -n "#1" $gsl_post \
| head -1 \
| awk -F: '{print $1}'`
# Source config website (DATAS)
source "$gsl_this_conf_domain/$gsl_find_domain.conf"
# Get Needed Headers DATAS
gsl__get_needed_headers
# Get extra Headers DATAS
#gsl_header_images=`gsl__get_header "$gsl_marker_image" "$gsl_post"`
gsl__post_content_only
# Code readability a11y
gsl_a11y_post=`mktemp`
}
#=======================================================================

View File

@ -45,8 +45,10 @@ do
# From COMMAND [OPT]
case "$1" in
check)
gsl_process="chk"
if ! [[ "$gsl_force_check" ]];then
gsl__db_compare_post_hash || continue
gsl__db_compare_post_hash
! [[ "$gsl_post_new_hash" ]] && continue
fi
gsl__logs_print \
@ -55,20 +57,19 @@ do
"Post" \
"$gsl_post" \
"${PWD}"
gsl_process="Checked"
gsl__all_checkers
;;
make)
gsl_process="Made"
gsl_process="wip"
gsl__db_compare_post_hash && continue
case "$gsl_db_post_status" in
Checked)
chk)
gsl__all_makers
;;
Made)
wip)
if [[ "$gsl_force_make" ]];then
gsl__all_makers
else
@ -78,6 +79,7 @@ do
"Make" \
"$gsl_post already Converted" \
"$gsl_file_db_posts"
gsl_checker_war=true
continue
fi
;;