AJAX
2 years ago
Admin_Page
2 years ago
Date_Range
2 years ago
Filter_Lists
2 years ago
Interval
2 years ago
Menu_Bar_Stats
2 years ago
Migrations
2 years ago
Models
2 years ago
Public_API
2 years ago
Rows
2 years ago
Statistics
2 years ago
Tables
2 years ago
Utils
2 years ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
2 years ago
Chart.php
2 years ago
Chart_Geo.php
2 years ago
Cron_Manager.php
2 years ago
Current_Traffic_Finder.php
2 years ago
Dashboard_Options.php
2 years ago
Dashboard_Widget.php
2 years ago
Database.php
2 years ago
Database_Manager.php
2 years ago
Email_Chart.php
2 years ago
Email_Reports.php
2 years ago
Empty_Report_Option.php
2 years ago
Env.php
2 years ago
Filters.php
2 years ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Manager.php
2 years ago
Geoposition.php
2 years ago
Icon_Directory.php
2 years ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
2 years ago
Independent_Analytics.php
2 years ago
Interrupt.php
2 years ago
Known_Referrers.php
2 years ago
Plugin_Conflict_Detector.php
2 years ago
Query.php
2 years ago
Quick_Stats.php
2 years ago
REST_API.php
2 years ago
Real_Time.php
2 years ago
Report.php
2 years ago
Report_Finder.php
2 years ago
Report_Options_Parser.php
2 years ago
Resource_Identifier.php
2 years ago
Settings.php
2 years ago
Sort_Configuration.php
2 years ago
Track_Resource_Changes.php
2 years ago
View.php
2 years ago
View_Counter.php
2 years ago
Visitors_Over_Time_Finder.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
WooCommerce_Order.php
2 years ago
WooCommerce_Referrer_Meta_Box.php
2 years ago
Track_Resource_Changes.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Models\Page_Author_Archive; |
| 6 | use IAWP\Models\Page_Post_Type_Archive; |
| 7 | use IAWP\Models\Page_Singular; |
| 8 | use IAWPSCOPED\Illuminate\Database\Query\JoinClause; |
| 9 | use IAWPSCOPED\Proper\Periodic; |
| 10 | /** @internal */ |
| 11 | class Track_Resource_Changes |
| 12 | { |
| 13 | public function __construct() |
| 14 | { |
| 15 | \add_action('wp_after_insert_post', [$this, 'handle_updated_post'], 10, 1); |
| 16 | \add_action('profile_update', [$this, 'handle_updated_author']); |
| 17 | if (Periodic::check('iawp_last_updated_post_type_cache', 'PT1M')) { |
| 18 | \add_action('registered_post_type', [$this, 'handle_registered_post_type']); |
| 19 | } |
| 20 | } |
| 21 | public function handle_updated_post($post_id) |
| 22 | { |
| 23 | $post = \get_post($post_id); |
| 24 | if (\is_null($post) || $post->post_status === 'trash') { |
| 25 | return; |
| 26 | } |
| 27 | $row = (object) ['resource' => 'singular', 'singular_id' => $post_id]; |
| 28 | $page = new Page_Singular($row); |
| 29 | $page->update_cache(); |
| 30 | $campaigns_table = \IAWP\Query::get_table_name(\IAWP\Query::CAMPAIGNS); |
| 31 | $sessions_table = \IAWP\Query::get_table_name(\IAWP\Query::SESSIONS); |
| 32 | $views_table = \IAWP\Query::get_table_name(\IAWP\Query::VIEWS); |
| 33 | $resources_table = \IAWP\Query::get_table_name(\IAWP\Query::RESOURCES); |
| 34 | \IAWP\Illuminate_Builder::get_builder()->from($campaigns_table, 'campaigns')->join("{$sessions_table} AS sessions", function (JoinClause $join) { |
| 35 | $join->on('sessions.campaign_id', '=', 'campaigns.campaign_id'); |
| 36 | })->join("{$views_table} AS views", function (JoinClause $join) { |
| 37 | $join->on('views.id', '=', 'sessions.initial_view_id'); |
| 38 | })->join("{$resources_table} AS resources", function (JoinClause $join) { |
| 39 | $join->on('resources.id', '=', 'views.resource_id'); |
| 40 | })->where('resources.singular_id', '=', $post_id)->update(['campaigns.landing_page_title' => $page->title()]); |
| 41 | } |
| 42 | public function handle_updated_author($user_id) |
| 43 | { |
| 44 | $row = (object) ['resource' => 'author', 'author_id' => $user_id]; |
| 45 | $page = new Page_Author_Archive($row); |
| 46 | $page->update_cache(); |
| 47 | } |
| 48 | public function handle_registered_post_type($post_type) |
| 49 | { |
| 50 | $post_type_object = \get_post_type_object($post_type); |
| 51 | if ($post_type_object->_builtin == \false) { |
| 52 | $row = (object) ['resource' => 'post_type_archive', 'post_type' => $post_type]; |
| 53 | $page = new Page_Post_Type_Archive($row); |
| 54 | $page->update_cache(); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 |