New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces JSON format function #67

Merged
merged 1 commit into from Feb 7, 2018

Conversation

Projects
None yet
4 participants
@iArren
Contributor

iArren commented May 15, 2017

Function json_format adds unnecessary spaces and newlines to the JSON.
So, added standart mechanism for pretty printing.

Replaces JSON format function
Function json_format adds unnecessary spaces and newlines to the JSON.
So, added standart mechanism for pretty printing.
@shoeper

This comment has been minimized.

Show comment
Hide comment
@shoeper

shoeper May 16, 2017

The possible errors stuff looks helpful, though.

shoeper commented May 16, 2017

The possible errors stuff looks helpful, though.

@m42e

This comment has been minimized.

Show comment
Hide comment
@m42e

m42e May 18, 2017

Collaborator

Not using the standard method was intentionally to prodive a bit more information if something is not correct as shoeper mentioned.

Collaborator

m42e commented May 18, 2017

Not using the standard method was intentionally to prodive a bit more information if something is not correct as shoeper mentioned.

@immae

This comment has been minimized.

Show comment
Hide comment
@immae

immae Dec 2, 2017

The problem is that after saving the configuration twice the json config become unreadable (the processing is not idempotent and adds newlines after each iteration)

This would allow to have both error messages and correct view:

diff --git a/init.php b/init.php
index 3c0f2f9..1aad146 100644
--- a/init.php
+++ b/init.php
@@ -600,10 +600,11 @@ class Feediron extends Plugin implements IHandler
                        return false;
                }
 
-               $this->host->set($this, 'json_conf', Feediron_Json::format($json_conf));
+                $new_conf = json_encode(json_decode($json_conf), JSON_PRETTY_PRINT);
+                $this->host->set($this, 'json_conf', $new_conf);
                $json_reply['success'] = true;
                $json_reply['message'] = __('Configuration saved.');
-               $json_reply['json_conf'] = Feediron_Json::format($json_conf);
+                $json_reply['json_conf'] = $new_conf;
                echo json_encode($json_reply);
        }
 

immae commented Dec 2, 2017

The problem is that after saving the configuration twice the json config become unreadable (the processing is not idempotent and adds newlines after each iteration)

This would allow to have both error messages and correct view:

diff --git a/init.php b/init.php
index 3c0f2f9..1aad146 100644
--- a/init.php
+++ b/init.php
@@ -600,10 +600,11 @@ class Feediron extends Plugin implements IHandler
                        return false;
                }
 
-               $this->host->set($this, 'json_conf', Feediron_Json::format($json_conf));
+                $new_conf = json_encode(json_decode($json_conf), JSON_PRETTY_PRINT);
+                $this->host->set($this, 'json_conf', $new_conf);
                $json_reply['success'] = true;
                $json_reply['message'] = __('Configuration saved.');
-               $json_reply['json_conf'] = Feediron_Json::format($json_conf);
+                $json_reply['json_conf'] = $new_conf;
                echo json_encode($json_reply);
        }
 

@m42e m42e merged commit cefd41f into feediron:master Feb 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment