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 # Get Post Hash & Status From Database
#====================================================================== #======================================================================
gsl__db_get_post_datas() { gsl__db_get_post_datas() {
gsl_db_post_hash=0
if [[ -f "$gsl_file_db_post" ]];then if [[ -f "$gsl_file_db_post" ]];then
gsl_db_post_hash=` gsl_db_post_hash=`
awk -F: 'NR == 1 {print $3}' \ awk -F: 'NR == 1 {print $3}' \
"$gsl_file_db_post"` "$gsl_file_db_post"`
! [[ "$gsl_db_post_hash" ]] \
&& gsl_db_post_hash=0
gsl_db_post_status=` gsl_db_post_status=`
awk -F: 'NR == 2 {print $2}' \ awk -F: 'NR == 2 {print $2}' \
"$gsl_file_db_post"` "$gsl_file_db_post"`
@ -27,37 +29,68 @@ fi
# Get Post Hash and Compare from Database # Get Post Hash and Compare from Database
#====================================================================== #======================================================================
gsl__db_compare_post_hash() { gsl__db_compare_post_hash() {
! (( $gsl_post_hash == $gsl_db_post_hash )) \ gsl_checker_war=true
&& gsl__logs_print \ if ! (( $gsl_post_hash == $gsl_db_post_hash ));then
gsl__logs_print \
"$gsl_log_w" \ "$gsl_log_w" \
"Post" \ "Post" \
"Hash" \ "Hash" \
"$gsl_post Changed ($gsl_post_hash)" \ "$gsl_post Changed ($gsl_post_hash)" \
"${PWD}/$gsl_post" \ "${PWD}/$gsl_post"
&& gsl_checker_war=true \ gsl_post_new_hash=true
&& return 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 # Set Post Status in Database according to proceess
#====================================================================== #======================================================================
gsl__db_set_post_status() { gsl__db_set_post_status() {
echo "D> DB:$gsl_file_db_post $gsl_process > $gsl_db_post_status"
case "$gsl_process" in case "$gsl_process" in
Checked) chk)
case "$gsl_db_post_status" in case "$gsl_db_post_status" in
Checked) chk)
gsl__db_compare_post_hash || return # Do Nothing if same Hash gsl__db_compare_post_hash
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
gsl__db_create_post gsl__db_create_post
;; ;;
Made) wip)
return gsl__db_compare_post_hash
;; [[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
Online) gsl_process="wip"
return
;;
*)
gsl__db_create_post 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
;; ;;
esac esac
@ -67,6 +100,7 @@ esac
# Create DB File from Data Post # Create DB File from Data Post
#====================================================================== #======================================================================
gsl__db_create_post() { gsl__db_create_post() {
echo "D> DB: $gsl_process > $gsl_db_post_status > $gsl_checker_err"
if [[ "$gsl_checker_err" ]];then if [[ "$gsl_checker_err" ]];then
[[ -f "$gsl_file_db_post" ]] \ [[ -f "$gsl_file_db_post" ]] \
&& rm -f "$gsl_file_db_post" \ && rm -f "$gsl_file_db_post" \
@ -81,6 +115,11 @@ fi
touch "$gsl_file_db_post" touch "$gsl_file_db_post"
# Check webserver files
gsl__page_prepare_datas
[[ -f $gsl_srv_wip_page ]] \
&& gsl_process=wip
# Main Print # Main Print
printf '%s\n%s\n%s\n' \ printf '%s\n%s\n%s\n' \
"Post:${PWD}/$gsl_post:$gsl_post_hash:$gsl_post_size" \ "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" 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 # Get Datas for Post/Page
#---------------------------------------------------------------------- #----------------------------------------------------------------------
gsl__page_prepare_datas() { gsl__page_prepare_datas() {
echo "D> $gsl_this_conf_domain" 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 # Check for Files & Folders in server
gsl_srv_wip="$gsl_site_server/$gsl_site_ndd/wip" 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 # Post or Page
case "$gsl_post_type" in case "$gsl_post_type" in
@ -59,7 +75,7 @@ gsl_uri_site_logo="$gsl_uri/templates/$gsl_site_logo"
#---------------------------------------------------------------------- #----------------------------------------------------------------------
gsl__check_srv_files() { gsl__check_srv_files() {
if [[ -f "$1" ]];then if [[ -f "$1" ]];then
echo "! Replaced Page: $1" echo "! Replace Page: $1"
fi fi
} }
@ -68,23 +84,31 @@ fi
#====================================================================== #======================================================================
gsl__page_create_listing() { gsl__page_create_listing() {
# Check if Post is in list ; Status Made # Check if Post is in list ; Status Made
[[ "$gsl_db_post_status" == "Made" ]] \ case "$gsl_db_post_status" in
&& gsl__logs_print \ wip|www)
gsl__logs_print \
"$gsl_log_i" \ "$gsl_log_i" \
"Post" \ "Post" \
"Make" \ "Make" \
"$gsl_post already added to Latest listings" \ "$gsl_post already added to Latest listings" \
"$gsl_file_db_posts" \ "$gsl_file_db_posts"
&& return return
;;
esac
touch "$gsl_dir_domain_tpl/last-posts-list.html" touch "$gsl_dir_domain_tpl/last-posts-list.html"
gsl_max_posts_list=5 gsl_list_max_posts=5
gsl_cur_posts_list=`cat "$gsl_dir_domain_tpl/last-posts-list.html" | wc -l` gsl_list_lines_per_post=5
if (( $((gsl_cur_posts_list )) >= 25 ));then gsl_list_max_lines=$(( gsl_list_max_posts * gsl_list_lines_per_post))
echo "D> $gsl_cur_posts_list * $gsl_max_posts_list" gsl_list_cur_lines=`
for i in `seq 1 5`; 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 do
sed -i "1d" "$gsl_dir_domain_tpl/last-posts-list.html" sed -i "1d" "$gsl_dir_domain_tpl/last-posts-list.html"
done done

View File

@ -15,8 +15,13 @@
#======================================================================= #=======================================================================
gsl__all_makers() { gsl__all_makers() {
unset gsl_check_done unset gsl_check_done
# Code readability a11y
gsl_a11y_post=`mktemp`
gsl__prepare_makers gsl__prepare_makers
gsl__page_prepare_datas gsl__page_prepare_datas
mkdir -p "$gsl_srv_wip"
gsl__srv_sync
# Create Listng Page # Create Listng Page
gsl__page_create_listing gsl__page_create_listing
@ -76,18 +81,9 @@ grep -n "#1" $gsl_post \
| head -1 \ | head -1 \
| awk -F: '{print $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 # Get extra Headers DATAS
#gsl_header_images=`gsl__get_header "$gsl_marker_image" "$gsl_post"` #gsl_header_images=`gsl__get_header "$gsl_marker_image" "$gsl_post"`
gsl__post_content_only gsl__post_content_only
# Code readability a11y
gsl_a11y_post=`mktemp`
} }
#======================================================================= #=======================================================================

View File

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