Assembly line workers/Data

From Apibot
Jump to: navigation, search

The Data workers are modifying in different ways the data that is transmitted between the line objects.

All are situated in the directory interfaces/line/workers/data.

Data block changing workers

These objects work on an entire data block (which includes not only a data element, eg. a wiki page, but also the type of the data element and possibly a "key" that distinguishes the element in some way).

All data block workers are situated in the subdirectory block.

Class name Task Creation params Public properties Notes
Worker_DataBlock_Copy Copies a data block Apibot core, New block key (optional at creation, but must be set at processing) $new_key If a block with the new key already exists, it will be overwritten
Worker_DataBlock_Rename Renames a data block Apibot core, New block key (optional at creation, but must be set at processing) $new_key If a block with the new key already exists, it will be overwritten
Worker_DataBlock_Set Sets a data block to the line object default data key Apibot core If a block with the default data key already exists, it will be overwritten
Worker_DataBlock_Swap Swaps a data block with another one Apibot core, Other block key (optional at creation, but must be set at processing) $key2 If one of the data blocks does not exist, the other will be effectively renamed
Worker_DataBlock_Unset Unsets the data block with the line object default data key Apibot core

Data type changing workers

These objects work on the data element type.

The types of the data elements are MIME-like strings: a data format, separated by a slash from the data type marker. For example: "array/page", "object/user", "numeric/pageid", "string/user" etc.

All data type workers are situated in the subdirectory type.

Class name Task Creation params Public properties Notes
Worker_DataType_Set Sets a given data element type to the line object default data key Apibot core, New data type (optional at creation, but must be set at processing) $new_type

Data element changing workers

These workers process the data element.

All data type workers are situated in the subdirectory element.

All have the following public properties:

  • $new_element_type - the new type of the changed data element. If unset, the data type of the element will not be changed.
  • $sublevels - allows changing not the entire data element, but its subelement. Assign to it the name of the sublevel, or an array with the names of the consecutive sublevels. Only arrays and objects can have subelements (members and properties respectively).

Some examples for the second property:

  • The data element is a page, and you want to change its timestamp - set $sublevels to "timestamp", or to array ( "timestamp" ).
  • The data element is array, which has under the key "object5" an object, which has a property $users. To this property is assigned an array, which has under key "2" some value that you want to replace. In this case, set $sublevels to array ( "object5", "users", "2" ).
  • The data element is an object whose property $people is not set. What happens if you set $sublevels to array ( "people", "John", "birthdate" ) to some date? In this case, the missing levels will be created automatically as arrays. That is, to $people will be assigned an array, then to its key "John" will be assigned another array, and then to its key "birthdate" will be assigned the date you supply.

From data

These workers set the data element from data of the same or another element / block in the signal. Most of them can also change the data in some way.

All workers are situated in the subdirectory element/set/from_data.

All have the following public properties:

  • $from_data_key - the data key of the block and element data must be taken from. If left unset, the default data key is used.
  • $from_sublevels - allows taking not the entire data element, but its subelement. See the explanation for the $sublevel property above for details.

There are several categories of workers that set data from data:

Common

Class name Task Creation params Public properties Notes
Worker_DataElement_CopyData Copies a given data (sub)element to the default data element (or its subelement), without changing it Apibot core
Worker_DataElement_MoveData Moves a given data (sub)element to the default data element (or its subelement), without changing it Apibot core
Worker_DataElement_FromValue Sets a given value to the default data element (or its subelement) Apibot core, Value to be set (optional, but must be set at processing) $value
Worker_DataElement_Counter Sets a counter to the default data element (or its subelement) Apibot core $start (start value),

$end (reset to start value after passing this),
$step (increase counter by this),
$repeat (repeat every value so many times),
$skip (skip so many signals after a value),
$skip_before (skip so many signals before counting start)

Checksums

These create different checksums of the source data element (or subelement).

All need string type of data. If they get a wrong kind of data, that will stop the processing of the data element.

Class name Task Creation params Public properties Notes
Worker_DataElement_CRC32 Produces a CRC32 checksum of the data element (must be string). Apibot core
Worker_DataElement_MD5 Produces an MD5 checksum of the data element (must be string). Apibot core
Worker_DataElement_SHA1 Produces a SHA1 checksum of the data element (must be string). Apibot core

Coders

These encode or decode the source data element (or subelement) in various ways.

Some of them might need a specific type of data. If they get a wrong kind of data, that will stop the processing of the data element.

Class name Task Creation params Public properties Notes
Worker_DataElement_Serialize Produces a PHP serialized form of the data element. Apibot core
Worker_DataElement_Unserialize Unserializes from PHP serialized form the data element. Apibot core $restored_element_type (must be set at processing)
Worker_DataElement_JSONEncode Produces an JSON-encoded form of the data element Apibot core The PHP JSON encoding is a superset of the standard one - things encoded by this worker might not be decoded by a non-PHP app!
Worker_DataElement_JSONDecode Restores a data (sub)element from JSON-encoded form (must be string). Apibot core $restored_element_type (must be set at processing)
Worker_DataElement_UUencode Produces an UUencoded form of the data element (must be string). Apibot core
Worker_DataElement_UUdecode Restores a data (sub)element from UUencoded form (must be string). Apibot core $restored_element_type (must be set at processing)

Math

These work on numeric data. Non-numeric data will cause the processing of the data element to stop there.

Class name Task Creation params Public properties Notes
Worker_DataElement_Math_Add Adds a specified value to the element it copies. Apibot core $add
Worker_DataElement_Math_Subtract Subtracts a specified value from the element it copies. Apibot core $subtract
Worker_DataElement_Math_SubtractFrom Subtracts the element it copies from a specified value. Apibot core $subtract_from
Worker_DataElement_Math_Multiply Multiplies the element it copies by a specified value. Apibot core $multiply
Worker_DataElement_Math_Divide Divides the element it copies by a specified value. Apibot core $divide
Worker_DataElement_Math_Round Rounds the element it copies. Apibot core $precision, $mode Works through the PHP round() function
Worker_DataElement_Math_Ceil Rounds up the element it copies. Apibot core Works through the PHP ceil() function
Worker_DataElement_Math_Floor Rounds down the element it copies. Apibot core Works through the PHP floor() function
Worker_DataElement_Math_Frac Returns the fractional part of the element it copies Apibot core
Worker_DataElement_Math_Min Returns the smaller of the copied element and a given value Apibot core $min
Worker_DataElement_Math_Max Returns the larger of the copied element and a given value Apibot core $max
Worker_DataElement_Math_Random Returns a random number between $min and $max Apibot core $min, $max Does not use source data element

String

These work on string data. Non-string data will cause the processing of the data element to stop there.

Class name Task Creation params Public properties Notes
Worker_DataElement_String_Extend Prepends and/or appends a string to the source data element (or subelement) Apibot core $prepend, $append
Worker_DataElement_String_Pad Pads the source data element (or subelement) with a string to a length, from left, right or both sides Apibot core $length, $with, $type = STR_PAD_RIGHT
Worker_DataElement_String_Repeat Repeats the source data element (or subelement) a given number of times Apibot core $count
Worker_DataElement_String_Trim Trims the leading and trailing spaces from the source data element (or subelement) Apibot core
Worker_DataElement_String_LTrim Trims the leading spaces from the source data element (or subelement) Apibot core
Worker_DataElement_String_RTrim Trims the trailing spaces from the source data element (or subelement) Apibot core
Worker_DataElement_String_Pos Returns the zero-based position of a given string within the source data element (or subelement) Apibot core $search (the string that must be found)
Worker_DataElement_String_Length Returns the length of the source data element (or subelement), in characters. Apibot core $mb = true, $encoding Multibyte by default; set $mb = false to switch that off. Specify $encoding to force a multibyte encoding.
Worker_DataElement_String_Substr Returns a substring of the source data element (or subelement), by start and length. Apibot core $start = 0, $length, $mb = true Multibyte by default; set $mb = false to switch that off. Leave $length unset to take from $start to the end of the data element.
Worker_DataElement_String_Replace Replaces in the source data element (or subelement) a given value or regex with another given value, up to a count of times Apibot core $match, $with, $count If $match starts with '/', it is treated as a PHP regex, otherwise as a string.
Worker_DataElement_String_ReplaceInto Replaces a given value into another given value with the source data element (or subelement), up to a count of times Apibot core $match, $into, $count If $match starts with '/', it is treated as a PHP regex, otherwise as a string.
Worker_DataElement_String_ToLower Lowercases the source data element (or subelement) Apibot core $mb = true Multibyte by default; set $mb = false to switch that off.
Worker_DataElement_String_ToUpper Uppercases the source data element (or subelement) Apibot core $mb = true Multibyte by default; set $mb = false to switch that off.
Worker_DataElement_String_UCFirst Uppercases the first letter of the source data element (or subelement) Apibot core $mb = true Multibyte by default; set $mb = false to switch that off.
Worker_DataElement_String_UCWords Uppercases the first letter of every word in the source data element (or subelement) Apibot core $mb = true Multibyte by default; set $mb = false to switch that off.

Transform

These transform the source data element (or subelement) in various ways.

Some of them might need a specific type of data. If they get a wrong kind of data, that will stop the processing of the data element.

Class name Task Creation params Public properties Notes
Worker_DataElement_ArrayToDataobject Converts a wiki-type data element (page, user, file...) from array form into object form. The object must be descendant of the Dataobject class. Apibot core $dataobject_class (name of the class to convert to)
Worker_DataElement_DataobjectToArray Converts a wiki-type data element (page, user, file...) from object form into array form. The object must be descendant of the Dataobject class. Apibot core
Worker_DataElement_Explode Explodes (by a delimiter) into array the data element (must be string). Apibot core $delimiter (must be set at processing)
Worker_DataElement_Implode Implodes (with an optional delimiter) to a string the data element (must be array). Apibot core $delimiter (default - "")

Wikivalues

These set to the data (sub)element the typical wikivalues (title, pageid, user, blockid...) from the source data element.

None of them has public properties, except the ones common for all workers that set data (sub)element from a data (sub)element.

The source data element must be of a type that can produce the wikivalue specified, or NULL will be returned (and set to the target) instead.

Class name Task Creation params Notes
Worker_DataElement_FromBlockid Sets the data (sub)element to the Blockid value from the source data element. Apibot core
Worker_DataElement_FromByUser Sets the data (sub)element to the By_User value from the source data element. Apibot core
Worker_DataElement_FromExpiry Sets the data (sub)element to the Expiry value from the source data element. Apibot core
Worker_DataElement_FromExtlink Sets the data (sub)element to the Extlink value from the source data element. Apibot core
Worker_DataElement_FromLogid Sets the data (sub)element to the Logid value from the source data element. Apibot core
Worker_DataElement_FromNsid Sets the data (sub)element to the Nsid value from the source data element. Apibot core
Worker_DataElement_FromPageid Sets the data (sub)element to the Pageid value from the source data element. Apibot core
Worker_DataElement_FromRcid Sets the data (sub)element to the Rcid value from the source data element. Apibot core
Worker_DataElement_FromRevid Sets the data (sub)element to the Revid value from the source data element. Apibot core
Worker_DataElement_FromSize Sets the data (sub)element to the Size value from the source data element. Apibot core
Worker_DataElement_FromTimestamp Sets the data (sub)element to the Timestamp value from the source data element. Apibot core
Worker_DataElement_FromTitle Sets the data (sub)element to the Title value from the source data element. Apibot core
Worker_DataElement_FromUser Sets the data (sub)element to the User value from the source data element. Apibot core
Worker_DataElement_FromUserid Sets the data (sub)element to the Userid value from the source data element. Apibot core

From parameters

These workers set the data element from a signal parameter or parameters group.

All workers are situated in the subdirectory element/set/from_params.

Class name Task Creation params Public properties Notes
Worker_DataElement_FromParam Sets the value of a given signal parameter to the data element (or its subelement) Apibot core, Paramgroup, Paramname (last two are optional at creation, but must be set at processing) $group, $name
Worker_DataElement_FromParamgroup Sets the value of a given signal parameters group to the data element (or its subelement) Apibot core, Paramgroup (optional at creation, but must be set at processing) $group

Other

Class name Task Creation params Public properties Notes
Worker_DataElement_Set Sets a given value to the data element (or its subelement) Apibot core, New data element (optional at creation, but must be set at processing) $new_element
Worker_DataElement_Unset Unsets the given data element level You may not unset the entire data element, as this does not make sense - only its subs. Unset the data block instead, or leave $sublevels empty to set the data element to NULL.

See also