BrowsersConverter.php
1 year ago
DataConverterInterface.php
4 years ago
FilterConverter.php
2 years ago
NumberConverter.php
1 year ago
PagesTitleConverter.php
1 year ago
PagesUrlConverter.php
1 year ago
PlatformConverter.php
4 years ago
ReferrersConverter.php
4 years ago
SearchEngineConverter.php
1 year ago
SearchQueryConverter.php
1 year ago
SubtableConverter.php
1 year ago
UserCityConverter.php
4 years ago
UserCountryConverter.php
4 years ago
UserRegionConverter.php
4 years ago
VisitorsConverter.php
1 year ago
VisitsTimeConverter.php
7 months ago
PagesTitleConverter.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WpMatomo\WpStatistics\DataConverters; |
| 4 | |
| 5 | use Piwik\DataTable; |
| 6 | use Piwik\Metrics; |
| 7 | use Piwik\Plugins\Actions\ArchivingHelper; |
| 8 | use Piwik\Tracker\Action; |
| 9 | |
| 10 | /** |
| 11 | * @package WpMatomo |
| 12 | * @subpackage WpStatisticsImport |
| 13 | */ |
| 14 | class PagesTitleConverter extends NumberConverter implements DataConverterInterface { |
| 15 | |
| 16 | public static function convert( array $wp_statistics_data ) { |
| 17 | // the title property is not set in newer versions of wp-statistics |
| 18 | foreach ( $wp_statistics_data as $key => $row ) { |
| 19 | if ( ! isset( $row['title'] ) ) { |
| 20 | $wp_statistics_data[ $key ]['title'] = get_the_title( $row['page_id'] ); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | $rows = self::aggregate_by_key( $wp_statistics_data, 'title' ); |
| 25 | |
| 26 | $data_tables = [ |
| 27 | Action::TYPE_PAGE_TITLE => new DataTable(), |
| 28 | ]; |
| 29 | ArchivingHelper::reloadConfig(); |
| 30 | foreach ( $rows as $row ) { |
| 31 | $title = $row->getColumn( 'label' ); |
| 32 | |
| 33 | $row->setColumn( Metrics::INDEX_PAGE_NB_HITS, $row['nb_visits'] ); |
| 34 | $row->setColumn( Metrics::INDEX_NB_VISITS, $row['nb_visits'] ); |
| 35 | $row->setColumn( Metrics::INDEX_NB_UNIQ_VISITORS, $row['nb_visits'] ); |
| 36 | $row->deleteColumn( 'nb_visits' ); |
| 37 | $row->deleteColumn( 'nb_uniq_visitors' ); |
| 38 | |
| 39 | $action_row = ArchivingHelper::getActionRow( $title, Action::TYPE_PAGE_TITLE, null, $data_tables ); |
| 40 | |
| 41 | $row->deleteColumn( 'label' ); |
| 42 | |
| 43 | $action_row->sumRow( $row, $copy_metadata = false ); |
| 44 | $action_row->setMetadata( 'page_title_path', $title ); |
| 45 | } |
| 46 | |
| 47 | // to aggregate the subtable data |
| 48 | ArchivingHelper::deleteInvalidSummedColumnsFromDataTable( $data_tables[ Action::TYPE_PAGE_TITLE ] ); |
| 49 | return $data_tables[ Action::TYPE_PAGE_TITLE ]; |
| 50 | } |
| 51 | } |
| 52 |