@@ -8,6 +8,7 @@ import WordPressShared
88import CoreTelephony
99import SafariServices
1010import Yosemite
11+ import Experiments
1112
1213extension NSNotification . Name {
1314 static let ZDPNReceived = NSNotification . Name ( rawValue: " ZDPNReceived " )
@@ -41,6 +42,7 @@ protocol ZendeskManagerProtocol: SupportManagerAdapter {
4142 func showTicketListIfPossible( from controller: UIViewController )
4243 func showSupportEmailPrompt( from controller: UIViewController , completion: @escaping onUserInformationCompletion )
4344 func getTags( supportSourceTag: String ? ) -> [ String ]
45+ func fetchSystemStatusReport( )
4446 func initialize( )
4547 func reset( )
4648}
@@ -92,6 +94,10 @@ struct NoZendeskManager: ZendeskManagerProtocol {
9294 [ ]
9395 }
9496
97+ func fetchSystemStatusReport( ) {
98+ // no-op
99+ }
100+
95101 func initialize( ) {
96102 // no-op
97103 }
@@ -146,6 +152,8 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
146152 private let stores = ServiceLocator . stores
147153 private let storageManager = ServiceLocator . storageManager
148154
155+ private let isSSRFeatureFlagEnabled = DefaultFeatureFlagService ( ) . isFeatureFlagEnabled ( . systemStatusReportInSupportRequest)
156+
149157 /// Controller for fetching site plugins from Storage
150158 ///
151159 private lazy var pluginResultsController : ResultsController < StorageSitePlugin > = createPluginResultsController ( )
@@ -202,6 +210,25 @@ final class ZendeskManager: NSObject, ZendeskManagerProtocol {
202210 return ippTags. map { $0. rawValue }
203211 }
204212
213+ /// Instantiates the SystemStatusReportViewModel as soon as the Zendesk instance needs it
214+ /// This generally happens in the SettingsViewModel if we need to fetch the site's System Status Report
215+ ///
216+ private lazy var systemStatusReportViewModel : SystemStatusReportViewModel = SystemStatusReportViewModel (
217+ siteID: ServiceLocator . stores. sessionManager. defaultSite? . siteID ?? 0
218+ )
219+
220+ /// Formatted system status report to be displayed on-screen
221+ ///
222+ private var systemStatusReport : String {
223+ systemStatusReportViewModel. statusReport
224+ }
225+
226+ /// Handles fetching the site's System Status Report
227+ ///
228+ func fetchSystemStatusReport( ) {
229+ systemStatusReportViewModel. fetchReport ( )
230+ }
231+
205232 func showNewRequestIfPossible( from controller: UIViewController ) {
206233 showNewRequestIfPossible ( from: controller, with: nil )
207234 }
@@ -638,11 +665,23 @@ private extension ZendeskManager {
638665 /// Without it, the tickets won't appear in the correct view(s) in the web portal and they won't contain all the metadata needed to solve a ticket.
639666 ///
640667 func createRequest( supportSourceTag: String ? ) -> RequestUiConfiguration {
668+
669+ var logsFieldID : Int64 = TicketFieldIDs . legacyLogs
670+ var systemStatusReportFieldID : Int64 = 0
671+ if isSSRFeatureFlagEnabled {
672+ /// If the feature flag is enabled, `legacyLogs` Field ID is used to send the SSR logs,
673+ /// and `logs` Field ID is used to send the logs.
674+ ///
675+ logsFieldID = TicketFieldIDs . logs
676+ systemStatusReportFieldID = TicketFieldIDs . legacyLogs
677+ }
678+
641679 let ticketFields = [
642680 CustomField ( fieldId: TicketFieldIDs . appVersion, value: Bundle . main. version) ,
643681 CustomField ( fieldId: TicketFieldIDs . deviceFreeSpace, value: getDeviceFreeSpace ( ) ) ,
644682 CustomField ( fieldId: TicketFieldIDs . networkInformation, value: getNetworkInformation ( ) ) ,
645- CustomField ( fieldId: TicketFieldIDs . logs, value: getLogFile ( ) ) ,
683+ CustomField ( fieldId: logsFieldID, value: getLogFile ( ) ) ,
684+ CustomField ( fieldId: systemStatusReportFieldID, value: systemStatusReport) ,
646685 CustomField ( fieldId: TicketFieldIDs . currentSite, value: getCurrentSiteDescription ( ) ) ,
647686 CustomField ( fieldId: TicketFieldIDs . sourcePlatform, value: Constants . sourcePlatform) ,
648687 CustomField ( fieldId: TicketFieldIDs . appLanguage, value: Locale . preferredLanguage) ,
@@ -657,12 +696,23 @@ private extension ZendeskManager {
657696
658697 func createWCPayRequest( supportSourceTag: String ? ) -> RequestUiConfiguration {
659698
699+ var logsFieldID : Int64 = TicketFieldIDs . legacyLogs
700+ var systemStatusReportFieldID : Int64 = 0
701+ if isSSRFeatureFlagEnabled {
702+ /// If the feature flag is enabled, `legacyLogs` Field ID is used to send the SSR logs,
703+ /// and `logs` Field ID is used to send the logs.
704+ ///
705+ logsFieldID = TicketFieldIDs . logs
706+ systemStatusReportFieldID = TicketFieldIDs . legacyLogs
707+ }
708+
660709 // Set form field values
661710 let ticketFields = [
662711 CustomField ( fieldId: TicketFieldIDs . appVersion, value: Bundle . main. version) ,
663712 CustomField ( fieldId: TicketFieldIDs . deviceFreeSpace, value: getDeviceFreeSpace ( ) ) ,
664713 CustomField ( fieldId: TicketFieldIDs . networkInformation, value: getNetworkInformation ( ) ) ,
665- CustomField ( fieldId: TicketFieldIDs . logs, value: getLogFile ( ) ) ,
714+ CustomField ( fieldId: logsFieldID, value: getLogFile ( ) ) ,
715+ CustomField ( fieldId: systemStatusReportFieldID, value: systemStatusReport) ,
666716 CustomField ( fieldId: TicketFieldIDs . currentSite, value: getCurrentSiteDescription ( ) ) ,
667717 CustomField ( fieldId: TicketFieldIDs . sourcePlatform, value: Constants . sourcePlatform) ,
668718 CustomField ( fieldId: TicketFieldIDs . appLanguage, value: Locale . preferredLanguage) ,
@@ -1087,7 +1137,8 @@ private extension ZendeskManager {
10871137 static let allBlogs : Int64 = 360000087183
10881138 static let deviceFreeSpace : Int64 = 360000089123
10891139 static let networkInformation : Int64 = 360000086966
1090- static let logs : Int64 = 22871957
1140+ static let legacyLogs : Int64 = 22871957
1141+ static let logs : Int64 = 10901699622036
10911142 static let currentSite : Int64 = 360000103103
10921143 static let sourcePlatform : Int64 = 360009311651
10931144 static let appLanguage : Int64 = 360008583691
0 commit comments