Copy Process List to new Input

Is is possible to copy an existing process list, to a new input?

The API can export a process list and apparently can import a process list, but that currently fails.

http://192.168.x.x/input/process/set?inputid=43411&processlist="1:110,34:111,1:76,34:77,2:0.001,process__kwh_accumulator:78,1:83"

Tried with the quotes and without

<br />
<b>Deprecated</b>:  explode(): Passing null to parameter #2 ($string) of type string is deprecated in <b>/var/www/emoncms/Modules/input/input_model.php</b> on line <b>601</b><br />
{"success":false,"message":"Input processlist was not updated"}

I’m anticipating that a PHP update has broken it :frowning:

It looks like the API is not working. It has been modified, but only on one side and the documentation not updated.

CoPilot tells me the set is expecting the processlist in a JSON format, but the get gives it in the old key value pair.

It also looks like you can’t just do it from a browser any more :man_facepalming:

That would be a PHP 8.1 deprecation.

It’ll still work as before, but if the right PHP debug settings are set, as you’ve seen, will result in the deprecation warnings being output.

1 Like

It doesn’t work at all.

I mean from the PHP PoV. It’ll spam you with deprecated warnings, but it won’t change the actual behaviour.

Are you using an old version of emoncms because the only explode on master is on Blaming emoncms/Modules/input/input_model.php at master · emoncms/emoncms · GitHub

fix clean_processlist_feeds · emoncms/emoncms@ffdad37 · GitHub seems to move some explode() around, and is in 11.9.8 onwards… And after that commit, only one explode() call exists in the file.

I haven’t done dug far enough to work out when that explode was on line 601, but it looks like it’s a while ago

There’s various PHP 8 fixes gone in too on various occasions…

1 Like

I’m on 11.9.13 although I haven’t restarted the machine since updating.

I fed the problem to CoPilot and it suggested the Set command was expecting a JSON format. CoPilot didn’t seem to think that would work directly as a URL though.

Shouldn’t necessarily have needed to restart… Unless there’s some long running process that is already loaded into memory etc.

But whatever is running doesn’t seem to match what is on more recent releases based on the errors on specific lines.

May be worth a restart, and see what messages you’re getting then.

1 Like

I’ll try a restart but, what should I expect?

If I use the process/get I get a key value pair. Should I be able to feed that into the process/set directly?

Have to say, getting the INput IDs is a PITA :frowning: Enhancement - Hover information over an Input name like the Feeds · Issue #1978 · emoncms/emoncms

[edit]
I get

[type or paste code here](http://192.168.x.x/input/process/set?inputid=43411&processlist=1:110,34:111,1:76,34:77,2:0.001,process__kwh_accumulator:78,1:83)
<br />
<b>Deprecated</b>:  json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in <b>/var/www/emoncms/Modules/process/process_model.php</b> on line <b>353</b><br />
{"success":false,"message":"Invalid process list format: "}

I’ve tried a single pair, a JSON Array and a JSON - both with just the accumulator setting. All the same error.

Hopefully errors (if applicable) that line up to code lines in use :wink:

I would presume so…

1 Like

No luck (added to above)

[edit]
I note -

But the get doesn’t output that :frowning: and the API help doesn’t mention it :exploding_head:

It’s shifted where the errors is coming from, at least - emoncms/Modules/process/process_model.php at master · emoncms/emoncms · GitHub

The error message given isn’t so helpful as it seems to be missing a parameter/similar after the :.

The deprecation warning is similarly from PHP 8.1, and should be worked around, but again, shouldn’t be causing the issue.

    public function validate_processlist($userid, $id, $processlist, $context_type = 0)
    {
        $userid = (int) $userid;
        $id = (int) $id;

        $processes = $this->process_list; // Get the process list
        $processes = $this->filter_valid($processes, $context_type); // Filter the process list based on context type

        // Process list expected in new JSON format
        $processlist = json_decode($processlist, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            return array('success' => false, 'message' => tr("Invalid process list format: "));
        }
        if (!is_array($processlist)) {
            return array('success' => false, 'message' => tr("Process list must be an array"));
        }

It seems a bit odd to be having a parameter passed in called processlist and then taking $this->process_list and filtering it to $processes and then doing the json_decode on the parameter passed in… That’s potentially work being done that won’t be used because of the error.

Trying to follow the data flow from GitHub isn’t the easiest, I’d have to open it in a proper IDE to have a better look.

1 Like

I think the first part should be to fix the get so it outputs something that the set can use directly.

A UI that allowed the copying of process lists would be really useful.

I’m trying to move the source of a couple of Feeds from one Input to new one :slight_smile:

There is some copying (the scissors etc) on the process list setup page…

But that’s broken on HTTP, see process list setup cut/copypaste doesn't work on HTTP · Issue #1971 · emoncms/emoncms · GitHub and process_ui.js: Add copy/paste fallback by reedy · Pull Request #1972 · emoncms/emoncms · GitHub (which I really need to test properly so it can be merged)

Oh, I never knew that existed. I’ve got internal HTTPS Certs so that isn’t an issue :slight_smile: Seems to work too. That solves my problem - thanks :grinning_face: