|
CInbox (Common-Inbox)
0.1
Common functionality for ingesting files for archiving.
|
Public Member Functions | |
| __construct ($logger) | |
| getLogger () | |
| resetItemList () | |
| setSourceFolder ($sourceFolder) | |
| setLogfile ($file) | |
| setConfigFile ($configFile=null) | |
| loadConfig () | |
| applyConfig () | |
| getName () | |
| getDefaultValues () | |
| initItemList ($sourceFolder) | |
| getItemCount () | |
| initInbox () | |
| initTempFiles () | |
| initItem () | |
| getNextItem () | |
| processItem () | |
| pause ($seconds, $update=5) | |
| run ($forever=false) | |
| getItemLogfile ($itemId, $folder) | |
| getProcessingFolder ($type) | |
| getStatusFolder ($status) | |
| setStatusBaseFolder ($folder) | |
| validateProcessingFolders ($processingFolders, $quiet=true) | |
| initProcessingFolders () | |
| switchStatus ($item, $status) | |
| removeDoneItems () | |
Temp folder handling. | |
| removeTempFolder () | |
| getTempFolder () | |
Public Attributes | |
Config options | |
| const | CONF_SECTION_INBOX = '__INBOX__' |
| Name of INI section that contains settings for the whole CInbox. | |
| const | CONF_INBOX_NAME = 'INBOX_NAME' |
| Name for Inbox. Must only contain alphanumeric ASCII characters. | |
| const | CONF_PAUSE_TIME = 'PAUSE_TIME' |
| Time to pause between each item (seconds) | |
| const | CONF_ITEMS_AT_ONCE = 'ITEMS_AT_ONCE' |
| Process max. this number of items in one run. | |
| const | CONF_KEEP_FINISHED = 'KEEP_FINISHED' |
| keep finished items for x days (0=delete immediately) TODO | |
| const | CONF_WAIT_FOR_ITEMS = 'WAIT_FOR_ITEMS' |
| Time to wait for new items to appear (minutes) | |
| const | CONF_MOVE_LOGFILES = 'MOVE_LOGFILES' |
| Move logfiles along with Items. | |
Miscellaneous | |
| const | DEFAULT_CONF_FILENAME = 'cinbox.ini' |
| Default filename of configuration file in Inbox folder. | |
| const | DEFAULT_TEMP_SUBFOLDER = 'cinbox-%s' |
| Name of temp folder. Placeholder will be replaced by Inbox name. | |
Protected Member Functions | |
| sortItems () | |
| addItem ($folderName) | |
Protected Attributes | |
Basics | |
| $logger | |
| Logging handler. | |
| $config | |
| CIConfig object. | |
| $name | |
Folder handling | |
| $sourceFolder | |
| Base folder where data for this inbox is located. | |
Temp folder handling | |
| $tempFolderRoot | |
| operating system folder where temporary files shall be stored. Default is 'sys_get_temp_dir()': /tmp, C:, etc. | |
| $tempFolder | |
| Folder where to write temporary files to. Created by 'initTempFiles()'. | |
| $tempReRun = false | |
| true/false: indicates whether temp folder already existed, indicating a re-run with unfinished items. | |
Item handling | |
| $itemList | |
| Array of to-do itemIds (key) and their folder as SplFileInfo object (value) | |
| $itemId | |
| ID of current Item. | |
| $item | |
| Item currently loaded/processed. | |
| $itemCount | |
| Counts items per run. | |
State keeping folders | |
| const | CONF_FOLDER_STATEKEEPING = 'DIR_STATEKEEPING' |
| Foldername for item-statekeeping. | |
| const | CONF_FOLDER_LOGS = 'DIR_LOGS' |
| Foldername for logfiles. | |
| const | CONF_FOLDER_TODO = 'DIR_TODO' |
| Foldername for items that are to be processed. | |
| const | CONF_FOLDER_IN_PROGRESS = 'DIR_IN_PROGRESS' |
| Foldername for items that are being processed. | |
| const | CONF_FOLDER_DONE = 'DIR_DONE' |
| Foldername for items that have been processed successfully. | |
| const | CONF_FOLDER_ERROR = 'DIR_ERROR' |
| Foldername for items that have errors. | |
| static | $processingFolders |
This class represents the actual CInbox. It takes care of handling and processing Items, as well as certain mechanisms and settings common to the CInbox.
| CInbox::addItem | ( | $ | folderName | ) | [protected] |
Adds an item folder to the CInbox' processing list.
| [in] | string | $folder | Full path name of this folder |
Apply the (hopefully already loaded) configuration options that are used in this class. Default values are applied, as configured in getDefaultValues().
Important: Config file must be loaded before (see loadConfig()).
Returns the default values for Inbox config settings.
Returns the number of items currently in the Inbox in state 'TO DO'.
| CInbox::getItemLogfile | ( | $ | itemId, |
| $ | folder | ||
| ) |
Returns the name of a logfile to use, based on an Item ID.
Returns the logger object used in this class.
| Logger |
| CInbox::getName | ( | ) |
Name of this Inbox. Must only contain alphanumeric characters, so it can be used in temp foldername.
Advance to next to-do item in itemList.
| CInbox::getProcessingFolder | ( | $ | type | ) |
Returns the actual foldername of a processing folder. $type must match the configuration strings.
Example: Logfile folder: $type = CInbox::CONF_FOLDER_LOGS
| CInbox::getStatusFolder | ( | $ | status | ) |
This function translates an Item status to its corresponding processing folder in the CInbox.
$status must be listed in CIItem::$itemStates;
| string | The name of the processing folder representing the given status. |
Returns the temporary folder for this Inbox.
| String |
Initializes the Inbox prior to being able to process any items.
This includes the following steps:
| boolean | Returns True if successful, False if an error occurred. |
| CInbox::initItemList | ( | $ | sourceFolder | ) |
Generates a list of item-folders in sourceFolder.
Checks if all processing folder are present and writable.
Initialize the use of temporary folder for this inbox.
The name for the temp-folder is built by using the inbox-label and sanitizing it as foldername. If the temp folder was created successfully, the property $tempFolder is set to the actual foldername.
If the temp-folder already exists, the property $tempReRun is set to True. This can be used throughout the class to know that there are "leftovers" from previous runs :)
This loads the INI file into $this->config and initializes placeholders. It does NOT yet apply the config. This is done in applyConfig().
| CInbox::pause | ( | $ | seconds, |
| $ | update = 5 |
||
| ) |
Waits a number of seconds and displays a countdown. $update defines how many seconds to wait between updating the countdown output.
This will NOT use the logging class to write on screen, since the output is only useful for a user watching. Not in the logs.
Process the current item. getNextItem()
Remove Items that have been successfully processed. Items are deleted if they are older than CONF_KEEP_FINISHED days.
This function cleans up things created during processing. It should be called before ending execution of the Inbox.
Cleans the item folder list by resetting it to an empty array.
| CInbox::run | ( | $ | forever = false | ) |
This is the main loop that iterates through items in the inbox.
| CInbox::setConfigFile | ( | $ | configFile = null | ) |
Sets the path and filename of the configuration file. If $configFile is empty, the default config file is assumed in the Inbox's source folder.
| CInbox::setLogfile | ( | $ | file | ) |
Sets the filename where to write log output to. If empty, then no logfile will be set.
| CInbox::setSourceFolder | ( | $ | sourceFolder | ) |
Set the folder where the items (=data-source) for this inbox is located.
| CInbox::setStatusBaseFolder | ( | $ | folder | ) |
Set the base folder for Inbox' state-keeping to $folder. By default, this is configured as CONF_FOLDER_STATEKEEPING option, and equals the Inbox' source folder.
| CInbox::sortItems | ( | ) | [protected] |
Sort item list alphabetically.
| CInbox::switchStatus | ( | $ | item, |
| $ | status | ||
| ) |
Changes the state of an Item to a different target status. Returns the target state folder on success. 'False' if a problem occurred.
| CInbox::validateProcessingFolders | ( | $ | processingFolders, |
| $ | quiet = true |
||
| ) |
Make sure that all processing folders are in place and have the right access rights, etc.
This method is designed to be called between execution loops to intercept errors caused by runtime-changes to the processing folders. For example: Folder removed or renamed between loops.
CInbox::$processingFolders [static] |
array(
self::CONF_FOLDER_STATEKEEPING => '.',
self::CONF_FOLDER_LOGS => 'log',
self::CONF_FOLDER_TODO => 'todo',
self::CONF_FOLDER_IN_PROGRESS => 'in_progress',
self::CONF_FOLDER_DONE => 'done',
self::CONF_FOLDER_ERROR => 'error',
)
List of all processing folders and their default values
1.7.6.1