aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2019-04-15 22:29:50 -0700
committerzotlabs <mike@macgirvin.com>2019-04-15 22:29:50 -0700
commitf7b281a65f914cae8611c3e4c9befcc2a20a057a (patch)
tree659c8b64743ac4cb894820eaa0f3ca47329b13d3 /util
parent0615709a7ab7bba66b2a07d593e84a35ed083edb (diff)
parent71f17a233e29a45304f43ee2329bfff1865c6917 (diff)
downloadvolse-hubzilla-f7b281a65f914cae8611c3e4c9befcc2a20a057a.tar.gz
volse-hubzilla-f7b281a65f914cae8611c3e4c9befcc2a20a057a.tar.bz2
volse-hubzilla-f7b281a65f914cae8611c3e4c9befcc2a20a057a.zip
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
Diffstat (limited to 'util')
-rw-r--r--util/po2php.php2
-rwxr-xr-xutil/storageconv137
2 files changed, 138 insertions, 1 deletions
diff --git a/util/po2php.php b/util/po2php.php
index 9ffcb64c4..73d9b454e 100644
--- a/util/po2php.php
+++ b/util/po2php.php
@@ -52,7 +52,7 @@ function po2php_run($argc,$argv) {
if ($l[0]=="#") $l="";
if (substr($l,0,15)=='"Plural-Forms: '){
$match=Array();
- preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
+ preg_match("|nplurals=([0-9]*);\s*plural=(.*)[;\\\\]|", $l, $match);
$cond = str_replace('n','$n',$match[2]);
$out .= 'if(! function_exists("' . 'string_plural_select_' . $lang .'")) {' . "\n";
$out .= 'function string_plural_select_' . $lang . '($n){'."\n";
diff --git a/util/storageconv b/util/storageconv
new file mode 100755
index 000000000..594ec14fb
--- /dev/null
+++ b/util/storageconv
@@ -0,0 +1,137 @@
+#!/usr/bin/env php
+<?php
+
+// Hubzilla thumbnails storage convertor
+function usage() {
+ echo <<< EOT
+Hubzilla thumbnails storage convertor
+
+Usage:
+ util/storageconv stats # show current stats
+ util/storageconv fs # move thumbnails from SQL to filesystem
+ util/storageconv db # move thumbnails from filesystem to SQL
+
+EOT;
+}
+
+require_once('include/cli_startup.php');
+
+cli_startup();
+
+if($argc == 1) {
+ usage();
+ killme();
+}
+
+if($argc == 2) {
+
+ $storage = (intval(get_config('system','filesystem_storage_thumbnails', 0)) > 0 ? 1 : 0);
+ echo 'Current storage set to: ' . ($storage ? 'filesystem' : 'SQL database') . PHP_EOL;
+ switch($argv[1]) {
+ case 'stats':
+ $x = q("SELECT COUNT(resource_id) AS qty FROM photo WHERE photo_usage = 0 and os_storage = 1");
+ echo 'Local images: ' . $x[0]['qty'] . PHP_EOL;
+ $x = q("SELECT COUNT(id) AS qty FROM photo WHERE resource_id IN (SELECT DISTINCT resource_id FROM photo WHERE photo_usage = 0 and os_storage = 1) AND imgscale > 0");
+ echo 'Thumbnails total: ' . $x[0]['qty'] . PHP_EOL;
+ $x = q("SELECT COUNT(id) AS qty FROM photo WHERE resource_id IN (SELECT DISTINCT resource_id FROM photo WHERE photo_usage = 0 and os_storage = 1) AND os_storage != %d AND imgscale > 0",
+ $storage
+ );
+ echo 'Thumbnails to convert: ' . $x[0]['qty'] . PHP_EOL;
+ break;
+
+ case 'fs':
+ if($storage == 0) {
+ echo 'Please set system.filesystem_storage_thumbnails to 1 before move thumbnails to filesystem storage' . PHP_EOL;
+ break;
+ }
+
+ $x = q("SELECT DISTINCT uid, resource_id FROM photo WHERE photo_usage = 0 and os_storage = 1");
+
+ if($x) {
+ foreach($x as $xx) {
+
+ $r = q("SELECT channel_address FROM channel WHERE channel_id = %d",
+ intval($xx['uid'])
+ );
+
+ $n = q("SELECT id, imgscale, content, os_path FROM photo WHERE resource_id = '%s' AND os_storage != %d AND imgscale > 0",
+ dbesc($xx['resource_id']),
+ $storage
+ );
+
+ echo count($n) . PHP_EOL;
+ foreach($n as $nn) {
+
+ echo '.';
+
+ $filename = 'store/' . $r[0]['channel_address'] . '/' . $nn['os_path'] . '-' . $nn['imgscale'];
+ if(! file_put_contents($filename, dbunescbin($nn['content']))) {
+ echo 'Failed to save file ' . $filename . PHP_EOL;
+ continue;
+ }
+
+ $z = q("UPDATE photo SET content = '%s', os_storage = 1 WHERE id = %d",
+ dbescbin($filename),
+ intval($nn['id'])
+ );
+ if(! $z) {
+ @unlink($filename);
+ echo 'Failed to update metadata for saved file ' . $filename . PHP_EOL;
+ }
+
+ }
+ }
+ }
+ break;
+
+ case 'db':
+ if($storage == 1) {
+ echo 'Please set system.filesystem_storage_thumbnails to 0 before move thumbnails to SQL database storage' . PHP_EOL;
+ break;
+ }
+
+ $x = q("SELECT DISTINCT resource_id FROM photo WHERE photo_usage = 0 and os_storage = 1");
+
+ if($x) {
+ foreach($x as $xx) {
+
+ $n = q("SELECT id, content FROM photo WHERE resource_id = '%s' AND os_storage != %d AND imgscale > 0",
+ dbesc($xx['resource_id']),
+ $storage
+ );
+
+ foreach($n as $nn) {
+
+ echo '.';
+
+ $filename = dbunescbin($nn['content']);
+ $content = file_get_contents($filename);
+ if($content) {
+
+ $z = q("UPDATE photo SET content = '%s', os_storage = 0 WHERE id = %d",
+ dbescbin($content),
+ intval($nn['id'])
+ );
+ if(! $z) {
+ echo 'Failed to update stored file metadata ' . $filename . PHP_EOL;
+ continue;
+ }
+
+ @unlink($filename);
+ }
+ else
+ echo 'Can not read file contents ' . $filename . PHP_EOL;
+ }
+ }
+ }
+ break;
+
+ default:
+ usage();
+ return;
+
+ }
+
+ echo PHP_EOL;
+}
+