PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / user-meta / application / cleanup-service.php

cleanup-service.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.9, at src/user-meta/application/cleanup-service.php

75 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\User_Meta\Application;
4
5 use Yoast\WP\SEO\User_Meta\Infrastructure\Cleanup_Repository;
6
7 /**
8 * Service with all usermeta cleanup queries.
9 */
10 class Cleanup_Service {
11
12 /**
13 * The additional contactmethods collector.
14 *
15 * @var Additional_Contactmethods_Collector
16 */
17 private $additional_contactmethods_collector;
18
19 /**
20 * The custom meta collector.
21 *
22 * @var Custom_Meta_Collector
23 */
24 private $custom_meta_collector;
25
26 /**
27 * The cleanup repository.
28 *
29 * @var Cleanup_Repository
30 */
31 private $cleanup_repository;
32
33 /**
34 * The constructor.
35 *
36 * @param Additional_Contactmethods_Collector $additional_contactmethods_collector The additional contactmethods collector.
37 * @param Custom_Meta_Collector $custom_meta_collector The custom meta collector.
38 * @param Cleanup_Repository $cleanup_repository The cleanup repository.
39 */
40 public function __construct(
41 Additional_Contactmethods_Collector $additional_contactmethods_collector,
42 Custom_Meta_Collector $custom_meta_collector,
43 Cleanup_Repository $cleanup_repository
44 ) {
45 $this->additional_contactmethods_collector = $additional_contactmethods_collector;
46 $this->custom_meta_collector = $custom_meta_collector;
47 $this->cleanup_repository = $cleanup_repository;
48 }
49
50 /**
51 * Deletes selected empty usermeta.
52 *
53 * @param int $limit The limit we'll apply to the cleanups.
54 *
55 * @return int|bool The number of rows that was deleted or false if the query failed.
56 */
57 public function cleanup_selected_empty_usermeta( int $limit ) {
58 $meta_to_check = $this->get_meta_to_check();
59
60 return $this->cleanup_repository->delete_empty_usermeta_query( $meta_to_check, $limit );
61 }
62
63 /**
64 * Gets which meta are going to be checked for emptiness.
65 *
66 * @return array<string> The meta to be checked for emptiness.
67 */
68 private function get_meta_to_check() {
69 $additional_contactmethods = $this->additional_contactmethods_collector->get_additional_contactmethods_keys();
70 $custom_meta = $this->custom_meta_collector->get_non_empty_custom_meta();
71
72 return \array_merge( $additional_contactmethods, $custom_meta );
73 }
74 }
75