Do RPC calls to transmission-daemon through php

Discussion of Transmission that doesn't fit in the other categories
johan.adriaans
Posts: 10
Joined: Wed Jun 30, 2010 10:56 pm

Re: Do RPC calls to transmission-daemon through php

Post by johan.adriaans »

Yep, new version is commited and available as a download. Great work brycec! I was really impressed with the results of your merge.
johan.adriaans
Posts: 10
Joined: Wed Jun 30, 2010 10:56 pm

Re: Do RPC calls to transmission-daemon through php

Post by johan.adriaans »

I suggested the class for the recources list, and there it is ;) Tnx again

http://www.transmissionbt.com/resources.php
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: Do RPC calls to transmission-daemon through php

Post by deadeyes »

@johan.adriaans
I did not yet tried the merged version.

I am now building on johan.adriaans version.
After basic implementation is done I will try to use this code.

However, there is a major bug in your code.

Code: Select all

235   protected function cleanRequestData ( $array )
236   {
237     if ( !is_array( $array ) || count( $array ) == 0 ) return null;
238     foreach ( $array as $index => $value ) {
239 print(json_encode($array));
240       if( is_array( $array[$index] ) ) $array[$index] = $this->cleanRequestData( $array[$index] ); // Recursion
241       if ( empty( $value ) && $value!=0) unset( $array[$index] );
242     }
243     return $array;
244   }
This has been added

Code: Select all

&& $value!=0
I spend alot of time to fix this bug.
If you create an array with values 0 in it (it does not matter if you use 0,2 or 0,0,2 , 1,3,0 ...) these are unset by your cleanRequestData function.
(resulting in 2 , 2 , 1,3).

Also if you unset entries in an array, json_encode does interprete all entries as 'key', 'value' pairs as all index numbers are not following (index++).
Example:

Code: Select all

$anarray = array(5,4,7,2);
unset($anarray[2]);
json_encode($anarray);
This results in

Code: Select all

{"0"=>5, "1"=>4, "3"=>2}
This is the wrong data type for transmission-daemon. Although it does return a success state, it does actually get executed. (I used "wanted-files" for setting the files to download)
After doing array_values:

Code: Select all

[5,4,2]
If you do unset, make sure you use $goodordervalue = array_values($thearray).
This will re-index the array.
johan.adriaans
Posts: 10
Joined: Wed Jun 30, 2010 10:56 pm

Re: Do RPC calls to transmission-daemon through php

Post by johan.adriaans »

@deadeyes

Tnx for pointing this out and working out a fix! I will test it and implement it in the current version.
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: Do RPC calls to transmission-daemon through php

Post by deadeyes »

Hi johan.adriaans,

You have been able to reproduce this issue?
Post Reply