3 * @package WPSEO\Admin|Google_Search_Console
7 * Class WPSEO_GSC_Marker
9 class WPSEO_GSC_Marker {
12 * @var WPSEO_GSC_Issues
14 private $crawl_issues;
37 * Setting up the needed API libs and return the result
39 * If param URL is given, the request is performed by a bulk action
43 public function __construct( $url = '' ) {
45 $this->result = $this->get_result();
49 * Getting the response for the AJAX request
52 public function get_response() {
57 * Setting the result, this method will check if current
61 private function get_result() {
62 if ( $this->can_be_marked_as_fixed() ) {
63 $service = new WPSEO_GSC_Service( WPSEO_GSC_Settings::get_profile() );
65 if ( $this->set_crawl_issues() && $this->send_mark_as_fixed( $service ) && $this->delete_crawl_issue() ) {
66 $this->update_issue_count( $service );
76 * Check if request is valid by verifying the posted nonce and return the URL if this one is set
80 private function can_be_marked_as_fixed() {
81 if ( $this->url !== '' ) {
89 * Storing the data belonging to the current issue, this data is needed in the 'mark as fixed' flow
93 private function set_crawl_issues() {
94 $this->platform = filter_input( INPUT_POST, 'platform' );
95 $this->category = filter_input( INPUT_POST, 'category' );
96 if ( $this->platform && $this->category ) {
97 $this->crawl_issues = new WPSEO_GSC_Issues( $this->platform, $this->category );
106 * Sending a request to the Google Search Console API to let them know we marked an issue as fixed.
108 * @param WPSEO_GSC_Service $service
112 private function send_mark_as_fixed( WPSEO_GSC_Service $service ) {
113 return $service->mark_as_fixed( $this->url, $this->platform, $this->category );
117 * Delete the crawl issue from the database
121 private function delete_crawl_issue() {
122 return $this->crawl_issues->delete_issue( $this->url );
126 * Getting the counts for current platform - category combination and update the score of it.
128 * @param WPSEO_GSC_Service $service
130 private function update_issue_count( WPSEO_GSC_Service $service ) {
131 $counts = new WPSEO_GSC_Count( $service );
134 $total_issues = $counts->get_issue_count( $this->platform, $this->category );
136 // Lower the current count with 1.
137 $total_issues = ( $total_issues - 1 );
139 // And update the count.
140 $counts->update_issue_count( $this->platform, $this->category, $total_issues );