SilverCart\Admin\Dev\Tasks\ProductImageImportTask
Provides a task to assign the uploaded product images.
- Author: Sebastian Diel <sdiel@pixeltricks.de>
- Copyright: 2017 pixeltricks GmbH
- License: see license file in modules root directory
Synopsis
class ProductImageImportTask
extends BuildTask
{
- // members
- private static string $segment = 'sc-image-importer';
- protected string $title = 'Import SilverCart Product Images';
- protected object $description = 'Task to import SilverCart product images. By ' . 'default, images should be stored in <strong><i>/public/assets/unassigned-product-images</i></strong>.<br/>' . ' The importer will run through the files and assign the images by' . ' file name. The file name should be equal with the product number.<br/>' . 'By default you can use the <i>"-"</i> sign to separate product number' . ' and a numeric index to add multiple images to one product.<br/>' . 'By adding another <i>"-"</i> behind the numeric index, you can also' . ' add an optional description (e.g. used as ALT tag).<br/>' . '<br/>' . 'Example image file names for a product with the product number' . ' <i>ABC1234D56</i>:' . '<ul>' . '<li>ABC1234D56.jpg</li>' . '<li>ABC1234D56-1.jpg</li>' . '<li>ABC1234D56-2.jpg</li>' . '<li>ABC1234D56-3-Left-side-view-of-my-awesome-product.jpg</li>' . '</ul>;
- private static string $relative_upload_folder = 'unassigned-product-images';
- private static string $import_is_running_file_name = '.scpii-is-running';
- private static string $import_is_installed_file_name = '.scpii-is-installed';
- private static string $image_name_separator = '-';
- private static array $image_endings = ;
- // methods
- public static array getFilesFromDir()
- public void run()
- protected void importFileData()
- protected void addNewImage()
- protected void addNewFile()
- protected void deleteExistingImages()
- protected void deleteExistingFiles()
- protected array getUploadedFiles()
- protected void markAsInstalled()
- protected void markAsRunning()
- protected void unmarkAsRunning()
- public static string get_import_source_path()
- public static string get_import_is_running_file_name()
- public static string get_import_is_running_file_path()
- public static string get_import_is_installed_file_name()
- public static string get_import_is_installed_file_path()
- public static bool is_installed()
- public static bool is_running()
- public static string get_absolute_upload_folder()
- public static string get_absolute_protected_upload_folder()
- public static string get_absolute_product_image_folder()
- public static string get_absolute_product_file_folder()
- public static string get_relative_upload_folder()
- public static void set_relative_upload_folder()
- public static string get_image_name_separator()
- public static void set_image_name_separator()
- // Inherited methods from CLITask
- public static array getRunningActions()
- protected static string getRunningTaskActionFilename()
- public static void removeTaskActionFile()
- public static void removeActionFilename()
- protected void initArgs()
- protected array getHelpDocs()
- public void help()
- public void helpNoAction()
- protected string getRunningActionFilename()
- protected void exitIfRunningAction()
- public void finishRunningActionOnBeforeExit()
- public bool isRunningAction()
- public void finishAction()
- public int getRunningActionStartTime()
- public bool isRunningCLI()
- public string getHTMLColor()
- public string getHTMLBgColor()
- public void printErrors()
- public void printInfos()
- public void printError()
- public void printInfo()
- public void printString()
- public void printProgressInfo()
- public void printProgressPercentageInfo()
- public void printProgressPercentageInfoWithTime()
- public void printMemoryInfo()
- public void printMemoryProgressInfo()
- public int printStartTime()
- public void printEndTime()
- public void loginSimulation()
- public bool isInSilentMode()
- public void setCliArg()
- public mixed getCliArg()
- public static string getTmpFolder()
- public static void setTmpFolder()
- protected void setLogFileNamePrefix()
- protected void setLogFileNameSuffix()
- public void Log()
- public string getXofY()
- protected array getFilesInDirectory()
- protected void extractZipFile()
- protected void deleteFiles()
- public static void add_error()
- public static array get_errors()
- public static void set_errors()
- public static void add_info()
- public static array get_infos()
- public static void set_infos()
- protected static string run_process_in_background()
- protected static bool is_process_running()
- public void addEmailInfo()
- public void addEmailError()
- public void addEmailWarning()
- public void sendEmail()
Hierarchy
Members
private
- $image_endings
—
array
File endings to use for the image import. Other endings will be imported as files. - $image_name_separator
—
string
Character to use to separate the prduct number and image name. - $import_is_installed_file_name
—
string
Name of the file that determines that the script installation is completed. - $import_is_running_file_name
—
string
Name of the temporary file that determines a running import process. - $relative_upload_folder
—
string
Relative path to the upload folder (relative to assets). - $segment
—
string
Set a custom url segment (to follow dev/tasks/)
protected
- $default_help_docs
—
array
Help docs. - $description
—
string
Describe the implications the task has, and the changes it makes. Accepts HTML formatting. - $emailInfos
—
array
List of infos to send by email. - $errors
—
array
List of occured errors - $finishRunningActionsOnBeforeExit
—
array
List of action callbacks to finish before self::exitIfRunningAction() is calling exit(). - $infos
—
array
List of occured infos - $lastProgressInfoLength
—
int
Contains the length of the last progress string printed by $this->printProgressInfo() - $log_file_name
—
string
Optional log file name. - $title
—
string
Shown in the overview on the {@link TaskRunner}. - $tmpFolder
—
string
Folder for temporary files
public
- $CLI_COLOR_BLACK
- $CLI_COLOR_BLUE
- $CLI_COLOR_CHANGE_BLACK
- $CLI_COLOR_CHANGE_BLUE
- $CLI_COLOR_CHANGE_CYAN
- $CLI_COLOR_CHANGE_GREEN
- $CLI_COLOR_CHANGE_MAGENTA
- $CLI_COLOR_CHANGE_RED
- $CLI_COLOR_CHANGE_WHITE
- $CLI_COLOR_CHANGE_YELLOW
- $CLI_COLOR_CYAN
- $CLI_COLOR_GREEN
- $CLI_COLOR_MAGENTA
- $CLI_COLOR_RED
- $CLI_COLOR_WHITE
- $CLI_COLOR_YELLOW
- $CLI_EMAIL_INFO_TYPE_ERROR
- $CLI_EMAIL_INFO_TYPE_INFO
- $CLI_EMAIL_INFO_TYPE_WARNING
- $RUNNING_ACTION_FILE_PREFIX
- $cli_args
—
array
Default CLI arguments
Methods
protected
- addNewFile() — Adds a new file to the given product.
- addNewImage() — Adds a new image to the given product.
- deleteExistingFiles() — Deletes the existing files of the given product.
- deleteExistingImages() — Deletes the existing images of the given product.
- getUploadedFiles() — Returns a list of not yet handled product image uploads.
- importFileData()
- markAsInstalled() — Adds the file that determines that the script installation is completed.
- markAsRunning() — Adds the file that determines a running import process.
- unmarkAsRunning() — Removes the file that determines a running import process.
public
- getFilesFromDir() — Returns the files (including drafts) from the given $dir.
- get_absolute_product_file_folder() — Returns the absolute path to the product image folder.
- get_absolute_product_image_folder() — Returns the absolute path to the product image folder.
- get_absolute_protected_upload_folder() — Returns the absolute path to the upload folder.
- get_absolute_upload_folder() — Returns the absolute path to the upload folder.
- get_image_name_separator() — Returns the character to use to separate the prduct number and image name.
- get_import_is_installed_file_name() — Returns the name of the file that determines that the script installation is completed.
- get_import_is_installed_file_path() — Returns the path to the file that determines that the script installation is completed.
- get_import_is_running_file_name() — Returns the name of the file that determines a running import process.
- get_import_is_running_file_path() — Returns the path to the file that determines a running import process.
- get_import_source_path() — Returns the source path to import the images from.
- get_relative_upload_folder() — Returns the relative path to the upload folder.
- is_installed() — Returns whether the script installation is completed.
- is_running() — Returns whether there is a currently running import process.
- run() — Runs this task.
- set_image_name_separator() — Sets the character to use to separate the prduct number and image name.
- set_relative_upload_folder() — Sets the relative path to the upload folder.
Inherited from SilverCart\Dev\CLITask
protected
- deleteFiles() — Deletes all files with the given extension out of the given directory.
- exitIfRunningAction() — Will exit the currently running program if the requested $action is already running. If $markAsStarted is set to true, the $action will automatically be marked as started if not running yet. If $printInfoMessage is set to false, nothing will be printed to the output.
- extractZipFile() — Extracts the given ZIP file into the given target folder.
- getFilesInDirectory() — Returns an array with all filepaths of the given file types in the given directory.
- getHelpDocs() — Returns the help docs.
- getRunningActionFilename() — Returns the file name (including path) for the running action.
- getRunningTaskActionFilename() — Returns the file name (including path) for the running $action of the given $task.
- initArgs() — Initializes the given arguments.
- is_process_running() — Checks whether a process with the given PID is running
- run_process_in_background() — Runs a command in background and returns its PID
- setLogFileNamePrefix() — Adds the given prefix to the log file name (separated with a ".").
- setLogFileNameSuffix() — Adds the given suffix to the log file name (separated with a ".").
public
- Log() — Writes a log entry
- addEmailError() — Adds an error message to send by email after the task is done.
- addEmailInfo() — Adds an information to send by email after the task is done.
- addEmailWarning() — Adds an warning message to send by email after the task is done.
- add_error() — Adds an error to the errors list
- add_info() — Adds an info to the infos list
- finishAction() — Will mark the requested $action as finished by removing the file marker.
- finishRunningActionOnBeforeExit() — Adds the given $action and $task combination to the callback list.
- getCliArg() — Returns the CLI argument with the given name
- getHTMLBgColor() — Returns the matching HTML color code to use as background color for the given CLI color code.
- getHTMLColor() — Returns the HTML color code for the given CLI color code.
- getRunningActionStartTime() — Returns the start time for the requested $action (if running).
- getRunningActions() — Returns a list of running actions.
- getTmpFolder() — Returns the folder for temporary files.
- getXofY() — Returns a padded X of Y string.
- get_errors() — Returns the errors
- get_infos() — Returns the infos
- help() — Will show the help.
- helpNoAction() — Will show the help.
- isInSilentMode() — Returns whether the task is in silent mode or not
- isRunningAction() — Checks whether the requested $action is already running. If $markAsStarted is set to true, the $action will automatically be marked as started if not running yet.
- isRunningCLI() — Returns whether the current task is running in CLI.
- loginSimulation() — Simulates a login by setting the session param for the logged in user ID
- printEndTime() — Prints end time information to the output.
- printError() — Prints the given error
- printErrors() — Prints the errors
- printInfo() — Prints the given info Colors: <ul> <li>30 -> black</li> <li>31 -> red</li> <li>32 -> green</li> <li>33 -> yellow</li> <li>34 -> blue</li> <li>35 -> magenta</li> <li>36 -> cyan</li> <li>37 -> white</li> </ul>
- printInfos() — Prints the infos
- printMemoryInfo() — Prints the current memory usage.
- printMemoryProgressInfo() — Prints the current memory usage as progress.
- printProgressInfo() — Prints the given progess info.
- printProgressPercentageInfo() — Prints the progress percentage info
- printProgressPercentageInfoWithTime() — Prints the progress percentage info
- printStartTime() — Prints the current time as start time and returns the timestamp.
- printString() — Prints and logs the given string.
- removeActionFilename() — Removes the file with the given $filename.
- removeTaskActionFile() — Removes the running $action file for the given $task.
- sendEmail() — Send the information email to the given $recipient.
- setCliArg() — Sets the CLI argument with the given name
- setTmpFolder() — Sets the folder for temporary files
- set_errors() — Sets the errors
- set_infos() — Sets the infos