hello all!
I have just started using Shaarli today on my self-hosted box and I am loving it! Everything I've been looking for, except one thing, which I believe I just need a point in the right direction.
I found the documentation for reading from the datastore, and I have come across this bit of code:
php -r 'print(json_encode(unserialize(gzinflate(base64_decode(preg_replace("!.*/\* (.+) \*/.*!", "$1", file_get_contents("/opt/www/links/data/datastore.p hp")))))));' | jq .
This works great! However, I will be setting up my server to parse the links and take action on select links.
I was wondering if it is possible to "reserialize/gzdeflate/base64_recode" the data after a parse, effectively I want to delete select notes after my machine has dealt with them
I am by no means an advanced web/php dev, so if anyone has any suggestions or help it would be greatly appreciated!
I'm not very good with bash, but this _seems_ to work:
#!/bin/bash
DATASTORE="./datastore.php"
# Extract the datastore
DATA=`php -r 'print(json_encode(unserialize(gzinflate(base64_decode(preg_replace("!.*/\* (.+) \*/.*!", "$1", file_get_contents($argv[1])))))));' -- $DATASTORE | jq .`
# Do stuff on your data
DATA=`echo $DATA | sed 's/cloud/butt/g'`
# Write your JSON data in a temp file
echo $DATA > ${DATASTORE}.tmp
# Write back your datastore
echo -n "<?php /* " > $DATASTORE
echo -n `php -r 'print(base64_encode(gzdeflate(serialize(json_decode(file_get_contents($argv[1]), true)))));' -- ${DATASTORE}.tmp` >> $DATASTORE
echo -n " */ ?>" >> $DATASTORE
rm -f ${DATASTORE}.tmp
Remember to save your data before using this.
Let us know how it goes, to add it in the doc.
thanks for this! i tested it out and after some fiddling got it to work (I destroyed the datastore a couple times already, and will probably break it a few more times before it's finalized.)
the code you included does not include any sort of error checking, so if there are errors in the sed portion the entire datastore becomes null.
Tomorrow I will be adjusting this code to fail a bit more gracefully. I will paste my code here when I am done, but this is very helpful and pointing me right where I need! thanks.
Yep, as I said, bash isn't really my thing. I think you can use set -e to stop the script if an error occures, but that won't stop you from corrupting your data. Thanks for the feedback.
why don't you use HTTP and e.g. curl to access shaarli the _normal_ way? Deleting entries should be rather simple, isn't it? If you need examples, have a look at https://github.com/mro/Shaarli-API-test/blob/master/tests/test-delete-ok.sh
I would highly discourage fiddling directly with private implementation details as the internal storage.
@ArthurHoaro @nodiscc as a sidenote: enabling bulk operation with comma-spearated lf_linkdate values would be nice.
Thanks for this, I will definitely check it out.
Was wanting to use curl initially but saw no ways of deleting links, guess I'm over-thinking it.
I will take a look at your examples and see if I can figure it out.
@mro What you need is an API. But it requires a lot of work and a clean code base (which become more and more the case :)
@andrunie Glad we could help. I'm closing this since your question has been answered.
@ArthurHoaro I'm fine with the existing HTTP request/response behavior as an implicit, de-facto API. While a rest-ish HTTP DELETE might be nice, the current design makes perfect sense. And where it's cumbersome, it mostly is such with a purpose (token as brute-force blocker).
Bulk deletion may not be a relevant use-case (isn't for me currently), but a comma-separated list may be an appealing extension.
I'd rather keep things as they are and stable, they do a perfect job now. And we have a interface that's downwards compatible quite long.
Are you only talking about deletion, or other operations? Bulk deletion would probably be rather easy to add.
only deletion. Others make no sense as bulk ops – at least without additional data per item.
However: remaining minimalistic and stable has priority over convenient machine access. So let's rather keep it as it is.
Most helpful comment
only deletion. Others make no sense as bulk ops – at least without additional data per item.
However: remaining minimalistic and stable has priority over convenient machine access. So let's rather keep it as it is.