eInfo = [ 'name' => __('[Schedule Deleted]', 'duplicator-pro'), 'storages' => __('N/A', 'duplicator-pro'), ]; } $packagesInfo[] = array_merge($scheduleInfo, ['count' => count($packageIds)]); } if (count($this->manualPackageIds) > 0) { $packagesInfo['manual'] = [ 'name' => __('Manual', 'duplicator-pro'), 'storages' => __('N/A', 'duplicator-pro'), 'count' => count($this->manualPackageIds), ]; } if (count($this->failedPackageIds) > 0) { $packagesInfo['failed'] = [ 'name' => __('Failed', 'duplicator-pro'), 'storages' => __('N/A', 'duplicator-pro'), 'count' => count($this->failedPackageIds), ]; } return $packagesInfo; } /** * Returns info about created schedules * * @return array */ private function getSchedulesInfo() { $schedulesInfo = []; foreach ($this->scheduleIds as $scheduleId) { if (($scheduleInfo = $this->getSingleScheduleInfo($scheduleId)) === false) { DUP_PRO_Log::trace("A Schedule with the ID {$scheduleId} was not found."); continue; } $schedulesInfo[] = $scheduleInfo; } return $schedulesInfo; } /** * Get schedule info or false if it doesn't exist * * @param int $scheduleId The schedule id * * @return array{'name': string, 'storages': string}|false */ private function getSingleScheduleInfo($scheduleId) { if (($schedule = DUP_PRO_Schedule_Entity::getById($scheduleId)) === false) { return false; } $result = []; $result['name'] = $schedule->name; $result['storages'] = ''; foreach ($schedule->storage_ids as $i => $storageId) { if (($storageInfo = $this->getSingleStorageInfo($storageId)) === false) { continue; } $seperator = ($i == count($schedule->storage_ids) - 1) ? '' : ', '; $result['storages'] .= $storageInfo['name'] . $seperator; } return $result; } /** * Returns info about created storages * * @return array */ private function getStoragesInfo() { $storagesInfo = []; foreach ($this->storageIds as $storageId) { if (($storageInfo = $this->getSingleStorageInfo($storageId)) === false) { DUP_PRO_Log::trace("A Storage with the ID {$storageId} was not found."); continue; } $storagesInfo[] = $storageInfo; } return $storagesInfo; } /** * Get storage info * * @param int $storageId The storage id * * @return array{'name': string, 'type': string}|false */ private function getSingleStorageInfo($storageId) { if (($storage = AbstractStorageEntity::getById($storageId)) === false) { return false; } return [ 'name' => $storage->getName(), 'type' => $storage->getStypeName(), ]; } /** * Get default recipient emails * * @return array */ public static function getDefaultRecipients() { $recipients = []; $adminEmail = get_option('admin_email'); if (!empty($adminEmail)) { $recipients[] = $adminEmail; } return $recipients; } /** * Get default recipient emails * * @return array */ public static function getRecipientSuggestions() { $recipients = []; foreach (self::getDefaultRecipients() as $recipient) { if (in_array($recipient, DUP_PRO_Global_Entity::getInstance()->getEmailSummaryRecipients())) { continue; } $recipients[] = $recipient; } return $recipients; } /** * Get all frequency options * * @return array */ public static function getAllFrequencyOptions() { return [ self::SEND_FREQ_NEVER => esc_html__('Never', 'duplicator-pro'), self::SEND_FREQ_DAILY => esc_html__('Daily', 'duplicator-pro'), self::SEND_FREQ_WEEKLY => esc_html__('Weekly', 'duplicator-pro'), self::SEND_FREQ_MONTHLY => esc_html__('Monthly', 'duplicator-pro'), ]; } /** * Get the frequency text displayed in the email * * @return string */ public static function getFrequencyText() { switch (DUP_PRO_Global_Entity::getInstance()->getEmailSummaryFrequency()) { case self::SEND_FREQ_DAILY: return esc_html__('day', 'duplicator-pro'); case self::SEND_FREQ_MONTHLY: return esc_html__('month', 'duplicator-pro'); case self::SEND_FREQ_WEEKLY: default: return esc_html__('week', 'duplicator-pro'); } } /** * Return entity type identifier * * @return string */ public static function getType() { return 'EmailSummary'; } }