]> git.plutz.net Git - confetti/blobdiff - categories/update_categories.sh
(re)introduced categories section
[confetti] / categories / update_categories.sh
similarity index 55%
rename from cards/categories/update_categories.sh
rename to categories/update_categories.sh
index c3b2e4c3f71dc9709b16b21322134e27cf31d0ef..944c3d2616601f2cbb83930b590168c25b4f39e2 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/zsh
+#!/bin/sh
 
-# Copyright 2016 Paul Hänsch
+# Copyright 2016, 2021 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
-. "$_EXEC"/pages/categories.sh
+. "$_EXEC"/cgilite/storage.sh
+. "$_EXEC"/pdiread.sh
 
 catfile="${_DATA}/mappings/categories"
 
-set_categories(){
-  card="${_DATA}/vcard/$1"
-  cats="$2"
-  cardcats="$(sed -nr 's;^CATEGORIES(\;[^":]+|\;"[^"]+")*:([^\r]+)\r?$;\2;p' "$card")"
+for card in "${_DATA}"/vcard/*.vcf; do
+  n='' postcats='' cardcats=''
+  vcf="$(pdi_load "$card")"
 
-  debug "CARD: $card"
-  debug "CATS: $cardcats"
-  debug "NEW:  $cats"
-  if [ "$cats" != "$cardcats" ]; then
+  n=1; while postcats="${postcats}${postcats:+,}$(POST "${card##*/}" $n)"; do n=$((n+1)); done
+  n=1; while cardcats="${cardcats}${cardcats:+,}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n+1)); done
+
+  if [ "${postcats}" != "${cardcats}" ] && LOCK "$card"; then
     sed -ri '
       /^CATEGORIES[;:]/d
-      /^END:VCARD *\r?$/iCATEGORIES:'"$cats"'\r
+      /^END;?:VCARD *\r?$/iCATEGORIES:'"${postcats%,}"'\r
     ' "${card}"
+    RELEASE "$card"
   fi
-}
-
-listcards |while read card; do
-  cardcats=''
-  for n in "$card" "$card"{0..100}; do
-    if [ -z "${_POST[$n]}" ]; then
-      set_categories "$card" "$cardcats"
-      break
-    fi
-    cardcats="${cardcats}${cardcats:+,}${_POST[$n]}"
-  done
 done
 
-redirect "?p=categories"
+REDIRECT /categories/