NotifyCommand
extends Command
in package
implements
TranslatorAwareInterface
Uses
TranslatorAwareTrait, LanguageInitializerTrait
Console command: notify users of scheduled searches.
Tags
Interfaces, Classes, Traits and Enums
- TranslatorAwareInterface
- Lightweight translator aware marker interface (used as an alternative to \Laminas\I18n\Translator\TranslatorAwareInterface, which requires an excessive number of methods to be implemented).
Table of Contents
- $iso8601 : string
- Useful date format value
- $limit : int
- Number of results to retrieve when performing searches
- $localeSettings : LocaleSettings
- $mailer : Mailer
- $mainConfig : Config
- $output : OutputInterface
- Output interface
- $renderer : PhpRenderer
- $resultsManager : PluginManager
- $scheduleOptions : array<string|int, mixed>
- $searchService : SearchServiceInterface
- $secretCalculator : SecretCalculator
- $translator : TranslatorInterface
- Translator
- $urlHelper : Url
- URL helper
- __construct() : mixed
- Constructor
- getTranslator() : TranslatorInterface
- Get translator object.
- getTranslatorLocale() : string
- Get the locale from the translator.
- setTranslator() : TranslatorAwareInterface
- Set a translator
- translate() : string
- Translate a string (or string-castable object)
- translateWithPrefix() : string
- Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
- addLanguageToTranslator() : void
- Configure a translator to support the requested language.
- buildEmail() : string
- Build the email message.
- configure() : void
- Configure the command.
- err() : void
- Display an error.
- execute() : int
- Run the command.
- extractTextDomain() : array<string|int, mixed>
- Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
- getDebugTranslation() : string
- Build a debug-mode translation
- getNewRecords() : array<string|int, mixed>|bool
- Given a search results object, fetch records that have changed since the last search. Return false on error.
- getObjectForSearch() : Results|bool
- Load and validate the results object associated with the search; return false if there is a problem.
- getTextDomains() : array<string|int, mixed>
- Look up all text domains.
- getUserForSearch() : UserEntityInterface|null
- Load and validate a user object associated with the search; return null if there is a problem.
- msg() : void
- Display a message.
- processViewAlerts() : void
- Send scheduled alerts for a view.
- sanitizeTranslationKey() : string
- Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
- sendEmail() : bool
- Try to send an email message to a user. Return true on success, false on error.
- setLanguage() : void
- Set up the translator language.
- translateString() : string
- Get translation for a string
- validateSchedule() : bool
- Validate the schedule (return true if we should send a message).
- warn() : void
- Display a warning.
Properties
$iso8601
Useful date format value
protected
string
$iso8601
= 'Y-m-d\\TH:i:s\\Z'
$limit
Number of results to retrieve when performing searches
protected
int
$limit
= 50
$localeSettings
protected
LocaleSettings
$localeSettings
$mailer
protected
Mailer
$mailer
$mainConfig
protected
Config
$mainConfig
$output
Output interface
protected
OutputInterface
$output
= null
$renderer
protected
PhpRenderer
$renderer
$resultsManager
protected
PluginManager
$resultsManager
$scheduleOptions
protected
array<string|int, mixed>
$scheduleOptions
$searchService
protected
SearchServiceInterface
$searchService
$secretCalculator
protected
SecretCalculator
$secretCalculator
$translator
Translator
protected
TranslatorInterface
$translator
= null
$urlHelper
URL helper
protected
Url
$urlHelper
Methods
__construct()
Constructor
public
__construct(SecretCalculator $secretCalculator, PhpRenderer $renderer, PluginManager $resultsManager, array<string|int, mixed> $scheduleOptions, Config $mainConfig, Mailer $mailer, SearchServiceInterface $searchService, LocaleSettings $localeSettings[, string|null $name = null ]) : mixed
Parameters
- $secretCalculator : SecretCalculator
-
Secret calculator
- $renderer : PhpRenderer
-
View renderer
- $resultsManager : PluginManager
-
Search results plugin manager
- $scheduleOptions : array<string|int, mixed>
-
Configured schedule options
- $mainConfig : Config
-
Top-level VuFind configuration
- $mailer : Mailer
-
Mail service
- $searchService : SearchServiceInterface
-
Search table
- $localeSettings : LocaleSettings
-
Locale settings object
- $name : string|null = null
-
The name of the command; passing null means it must be set in configure()
Return values
mixed —getTranslator()
Get translator object.
public
getTranslator() : TranslatorInterface
Return values
TranslatorInterface —getTranslatorLocale()
Get the locale from the translator.
public
getTranslatorLocale([string $default = 'en' ]) : string
Parameters
- $default : string = 'en'
-
Default to use if translator absent.
Return values
string —setTranslator()
Set a translator
public
setTranslator(TranslatorInterface $translator) : TranslatorAwareInterface
Parameters
- $translator : TranslatorInterface
-
Translator
Return values
TranslatorAwareInterface —translate()
Translate a string (or string-castable object)
public
translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —translateWithPrefix()
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
public
translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $prefix : string
-
Translation key prefix
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —addLanguageToTranslator()
Configure a translator to support the requested language.
protected
addLanguageToTranslator(TranslatorInterface $translator, LocaleSettings $settings, string $language) : void
Parameters
- $translator : TranslatorInterface
-
Translator
- $settings : LocaleSettings
-
Locale settings
- $language : string
-
Language to set up
Return values
void —buildEmail()
Build the email message.
protected
buildEmail(SearchEntityInterface $s, UserEntityInterface $user, Results $searchObject, array<string|int, mixed> $newRecords) : string
Parameters
- $s : SearchEntityInterface
-
Search table row
- $user : UserEntityInterface
-
User owning search row
- $searchObject : Results
-
Search results object
- $newRecords : array<string|int, mixed>
-
New results in search
Return values
string —configure()
Configure the command.
protected
configure() : void
Return values
void —err()
Display an error.
protected
err(string $msg) : void
Parameters
- $msg : string
-
Message to display
Return values
void —execute()
Run the command.
protected
execute(InputInterface $input, OutputInterface $output) : int
Parameters
- $input : InputInterface
-
Input object
- $output : OutputInterface
-
Output object
Tags
Return values
int —0 for success
extractTextDomain()
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
protected
extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
Return values
array<string|int, mixed> —getDebugTranslation()
Build a debug-mode translation
protected
getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
- $domain : string
-
Text domain
- $str : string
-
String to translate
- $tokens : array<string|int, mixed>
-
Tokens to inject into the translated string
Return values
string —getNewRecords()
Given a search results object, fetch records that have changed since the last search. Return false on error.
protected
getNewRecords(Results $searchObject, DateTime $lastTime) : array<string|int, mixed>|bool
Parameters
- $searchObject : Results
-
Search results object
- $lastTime : DateTime
-
Last notification time
Return values
array<string|int, mixed>|bool —getObjectForSearch()
Load and validate the results object associated with the search; return false if there is a problem.
protected
getObjectForSearch(SearchEntityInterface $s) : Results|bool
Parameters
- $s : SearchEntityInterface
-
Current search row.
Return values
Results|bool —getTextDomains()
Look up all text domains.
protected
getTextDomains() : array<string|int, mixed>
Return values
array<string|int, mixed> —getUserForSearch()
Load and validate a user object associated with the search; return null if there is a problem.
protected
getUserForSearch(SearchEntityInterface $s) : UserEntityInterface|null
Parameters
- $s : SearchEntityInterface
-
Current search row.
Return values
UserEntityInterface|null —msg()
Display a message.
protected
msg(string $msg) : void
Parameters
- $msg : string
-
Message to display
Return values
void —processViewAlerts()
Send scheduled alerts for a view.
protected
processViewAlerts() : void
Return values
void —sanitizeTranslationKey()
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
protected
sanitizeTranslationKey(string $key) : string
Parameters
- $key : string
-
Key to sanitize
Return values
string —Sanitized key
sendEmail()
Try to send an email message to a user. Return true on success, false on error.
protected
sendEmail(UserEntityInterface $user, string $message) : bool
Parameters
- $user : UserEntityInterface
-
User to email
- $message : string
-
Email message body
Return values
bool —setLanguage()
Set up the translator language.
protected
setLanguage(string $userLang) : void
Parameters
- $userLang : string
-
User language preference from database (may be empty).
Return values
void —translateString()
Get translation for a string
protected
translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
- $rawStr : string
-
String to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $domain : string = 'default'
-
Text domain (omit for default)
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
Return values
string —validateSchedule()
Validate the schedule (return true if we should send a message).
protected
validateSchedule(DateTime $todayTime, DateTime $lastTime, SearchEntityInterface $s) : bool
Parameters
- $todayTime : DateTime
-
The time the notification job started.
- $lastTime : DateTime
-
Last time notification was sent.
- $s : SearchEntityInterface
-
Search row to validate.
Return values
bool —warn()
Display a warning.
protected
warn(string $msg) : void
Parameters
- $msg : string
-
Message to display