Lines: 69.29%
| Line | Hits | Source |
|---|---|---|
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @file | |
| 5 | * Install/uninstall visitors module. | |
| 6 | */ | |
| 7 | ||
| 8 | use Drupal\Component\Utility\DeprecationHelper; | |
| 9 | use Drupal\Core\Extension\Requirement\RequirementSeverity; | |
| 10 | use Drupal\Component\Serialization\Yaml; | |
| 11 | use Drupal\Core\Entity\EntityTypeInterface; | |
| 12 | use Drupal\Core\StringTranslation\TranslatableMarkup; | |
| 13 | use Drupal\Core\Url; | |
| 14 | ||
| 15 | /** | |
| 16 | * Implements hook_install(). | |
| 17 | */ | |
| 18 | function visitors_install($is_syncing) { | |
| 19 | 3 | if ($is_syncing) { |
| 20 | 1 | return; |
| 21 | } | |
| 22 | 2 | if (!\Drupal::moduleHandler()->moduleExists('statistics')) { |
| 23 | 1 | return; |
| 24 | } | |
| 25 | 1 | $settings = \Drupal::service('config.factory')->getEditable('visitors.settings'); |
| 26 | 1 | $settings->set('counter.enabled', FALSE) |
| 27 | 1 | ->save(); |
| 28 | ||
| 29 | 1 | \Drupal::messenger()->addWarning(t( |
| 30 | 1 | 'The Statistics module is installed. <a href="@url">Convert the Statistics node views</a> to Visitors page views.', |
| 31 | 1 | ['@url' => Url::fromRoute('visitors.statistics_migrate')->toString()] |
| 32 | 1 | )); |
| 33 | ||
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Implements hook_schema(). | |
| 38 | */ | |
| 39 | function visitors_schema() { | |
| 40 | ||
| 41 | $schema['visitors_visit'] = [ | |
| 42 | 'fields' => [ | |
| 43 | 'id' => [ | |
| 44 | 'description' => 'Primary key', | |
| 45 | 'type' => 'serial', | |
| 46 | 'not null' => TRUE, | |
| 47 | ], | |
| 48 | 'visitor_id' => [ | |
| 49 | 'description' => 'Unique id, provided by the visitor', | |
| 50 | 'type' => 'varchar', | |
| 51 | 'length' => 32, | |
| 52 | 'not null' => FALSE, | |
| 53 | 'default' => NULL, | |
| 54 | ], | |
| 55 | 'uid' => [ | |
| 56 | 'description' => 'The user of the session', | |
| 57 | 'type' => 'varchar', | |
| 58 | 'length' => 32, | |
| 59 | 'not null' => FALSE, | |
| 60 | ], | |
| 61 | 'localtime' => [ | |
| 62 | 'description' => 'Seconds since midnight, in the local of the visitor', | |
| 63 | 'type' => 'int', | |
| 64 | 'size' => 'medium', | |
| 65 | 'not null' => FALSE, | |
| 66 | 'default' => NULL, | |
| 67 | ], | |
| 68 | 'returning' => [ | |
| 69 | 'description' => 'Is the visitor returning, or new', | |
| 70 | 'type' => 'int', | |
| 71 | 'size' => 'tiny', | |
| 72 | ], | |
| 73 | 'total_visits' => [ | |
| 74 | 'description' => 'Total visits', | |
| 75 | 'type' => 'int', | |
| 76 | 'not null' => TRUE, | |
| 77 | 'default' => 0, | |
| 78 | ], | |
| 79 | 'total_page_views' => [ | |
| 80 | 'description' => 'Total page views this visit', | |
| 81 | 'type' => 'int', | |
| 82 | 'not null' => TRUE, | |
| 83 | 'default' => 0, | |
| 84 | ], | |
| 85 | 'total_events' => [ | |
| 86 | 'description' => 'Total events this visit', | |
| 87 | 'type' => 'int', | |
| 88 | 'not null' => TRUE, | |
| 89 | 'default' => 0, | |
| 90 | ], | |
| 91 | 'entry' => [ | |
| 92 | 'description' => 'First page view', | |
| 93 | 'type' => 'int', | |
| 94 | 'not null' => FALSE, | |
| 95 | 'default' => NULL, | |
| 96 | ], | |
| 97 | 'entry_time' => [ | |
| 98 | 'description' => 'The time the visit was started', | |
| 99 | 'type' => 'int', | |
| 100 | 'not null' => FALSE, | |
| 101 | 'default' => NULL, | |
| 102 | ], | |
| 103 | 'exit' => [ | |
| 104 | 'description' => 'Last page view', | |
| 105 | 'type' => 'int', | |
| 106 | 'not null' => FALSE, | |
| 107 | 'default' => NULL, | |
| 108 | ], | |
| 109 | 'exit_time' => [ | |
| 110 | 'description' => 'The time the visit was ended', | |
| 111 | 'type' => 'int', | |
| 112 | 'not null' => FALSE, | |
| 113 | 'default' => NULL, | |
| 114 | ], | |
| 115 | 'total_time' => [ | |
| 116 | 'description' => 'The total time of the visit', | |
| 117 | 'type' => 'int', | |
| 118 | 'not null' => FALSE, | |
| 119 | 'default' => NULL, | |
| 120 | ], | |
| 121 | 'time_since_first' => [ | |
| 122 | 'description' => 'Seconds since the visitor\'s first visit', | |
| 123 | 'type' => 'int', | |
| 124 | 'not null' => FALSE, | |
| 125 | 'default' => NULL, | |
| 126 | ], | |
| 127 | 'time_since_last' => [ | |
| 128 | 'description' => 'Seconds since the visitor\'s last visit', | |
| 129 | 'type' => 'int', | |
| 130 | 'not null' => FALSE, | |
| 131 | 'default' => NULL, | |
| 132 | ], | |
| 133 | 'bot' => [ | |
| 134 | 'description' => 'Is the visitor a bot', | |
| 135 | 'type' => 'int', | |
| 136 | 'size' => 'tiny', | |
| 137 | 'not null' => FALSE, | |
| 138 | 'default' => NULL, | |
| 139 | ], | |
| 140 | 'bot_name' => [ | |
| 141 | 'description' => 'Device Detector bot name', | |
| 142 | 'type' => 'varchar', | |
| 143 | 'length' => 255, | |
| 144 | 'not null' => FALSE, | |
| 145 | 'default' => NULL, | |
| 146 | ], | |
| 147 | 'ai_agent' => [ | |
| 148 | 'description' => 'The visit was opened by an AI agent browser.', | |
| 149 | 'type' => 'int', | |
| 150 | 'size' => 'tiny', | |
| 151 | 'unsigned' => TRUE, | |
| 152 | 'not null' => TRUE, | |
| 153 | 'default' => 0, | |
| 154 | ], | |
| 155 | 'config_id' => [ | |
| 156 | 'description' => 'The fingerprint id', | |
| 157 | 'type' => 'varchar', | |
| 158 | 'length' => 16, | |
| 159 | 'not null' => TRUE, | |
| 160 | ], | |
| 161 | 'config_resolution' => [ | |
| 162 | 'description' => 'The screen resolution', | |
| 163 | 'type' => 'varchar', | |
| 164 | 'length' => 18, | |
| 165 | 'not null' => FALSE, | |
| 166 | 'default' => NULL, | |
| 167 | ], | |
| 168 | 'config_pdf' => [ | |
| 169 | 'description' => 'Has PDF support', | |
| 170 | 'type' => 'int', | |
| 171 | 'size' => 'tiny', | |
| 172 | 'not null' => FALSE, | |
| 173 | 'default' => NULL, | |
| 174 | ], | |
| 175 | 'config_flash' => [ | |
| 176 | 'description' => 'Has Flash support', | |
| 177 | 'type' => 'int', | |
| 178 | 'size' => 'tiny', | |
| 179 | 'not null' => FALSE, | |
| 180 | 'default' => NULL, | |
| 181 | ], | |
| 182 | 'config_java' => [ | |
| 183 | 'description' => 'Has Java support', | |
| 184 | 'type' => 'int', | |
| 185 | 'size' => 'tiny', | |
| 186 | 'not null' => FALSE, | |
| 187 | 'default' => NULL, | |
| 188 | ], | |
| 189 | 'config_quicktime' => [ | |
| 190 | 'description' => 'Has Quicktime support', | |
| 191 | 'type' => 'int', | |
| 192 | 'size' => 'tiny', | |
| 193 | 'not null' => FALSE, | |
| 194 | 'default' => NULL, | |
| 195 | ], | |
| 196 | 'config_realplayer' => [ | |
| 197 | 'description' => 'Has Realplayer support', | |
| 198 | 'type' => 'int', | |
| 199 | 'size' => 'tiny', | |
| 200 | 'not null' => FALSE, | |
| 201 | 'default' => NULL, | |
| 202 | ], | |
| 203 | 'config_windowsmedia' => [ | |
| 204 | 'description' => 'Has Windows Media support', | |
| 205 | 'type' => 'int', | |
| 206 | 'size' => 'tiny', | |
| 207 | 'not null' => FALSE, | |
| 208 | 'default' => NULL, | |
| 209 | ], | |
| 210 | 'config_silverlight' => [ | |
| 211 | 'description' => 'Has Silverlight support', | |
| 212 | 'type' => 'int', | |
| 213 | 'size' => 'tiny', | |
| 214 | 'not null' => FALSE, | |
| 215 | 'default' => NULL, | |
| 216 | ], | |
| 217 | 'config_cookie' => [ | |
| 218 | 'description' => 'Has cookie support', | |
| 219 | 'type' => 'int', | |
| 220 | 'size' => 'tiny', | |
| 221 | 'not null' => FALSE, | |
| 222 | 'default' => NULL, | |
| 223 | ], | |
| 224 | 'config_browser_engine' => [ | |
| 225 | 'description' => 'The browser engine', | |
| 226 | 'type' => 'varchar', | |
| 227 | 'length' => '10', | |
| 228 | 'not null' => FALSE, | |
| 229 | 'default' => NULL, | |
| 230 | ], | |
| 231 | 'config_browser_name' => [ | |
| 232 | 'description' => 'The browser name', | |
| 233 | 'type' => 'varchar', | |
| 234 | 'length' => '2', | |
| 235 | 'not null' => FALSE, | |
| 236 | 'default' => NULL, | |
| 237 | ], | |
| 238 | 'config_browser_version' => [ | |
| 239 | 'description' => 'The browser version', | |
| 240 | 'type' => 'varchar', | |
| 241 | 'length' => '20', | |
| 242 | 'not null' => FALSE, | |
| 243 | 'default' => NULL, | |
| 244 | ], | |
| 245 | 'config_client_type' => [ | |
| 246 | 'description' => 'The client type', | |
| 247 | 'type' => 'varchar', | |
| 248 | 'length' => '100', | |
| 249 | 'not null' => FALSE, | |
| 250 | 'default' => NULL, | |
| 251 | ], | |
| 252 | 'config_device_brand' => [ | |
| 253 | 'description' => 'The device brand', | |
| 254 | 'type' => 'varchar', | |
| 255 | 'length' => '100', | |
| 256 | 'not null' => FALSE, | |
| 257 | 'default' => NULL, | |
| 258 | ], | |
| 259 | 'config_device_model' => [ | |
| 260 | 'description' => 'The device model', | |
| 261 | 'type' => 'varchar', | |
| 262 | 'length' => '100', | |
| 263 | 'not null' => FALSE, | |
| 264 | 'default' => NULL, | |
| 265 | ], | |
| 266 | 'config_device_type' => [ | |
| 267 | 'description' => 'The device type', | |
| 268 | 'type' => 'varchar', | |
| 269 | 'length' => '100', | |
| 270 | 'not null' => FALSE, | |
| 271 | 'default' => NULL, | |
| 272 | ], | |
| 273 | 'config_os' => [ | |
| 274 | 'description' => 'The operating system', | |
| 275 | 'type' => 'varchar', | |
| 276 | 'length' => '3', | |
| 277 | 'not null' => FALSE, | |
| 278 | 'default' => NULL, | |
| 279 | ], | |
| 280 | 'config_os_version' => [ | |
| 281 | 'description' => 'The operating system version', | |
| 282 | 'type' => 'varchar', | |
| 283 | 'length' => '100', | |
| 284 | 'not null' => FALSE, | |
| 285 | 'default' => NULL, | |
| 286 | ], | |
| 287 | 'location_browser_lang' => [ | |
| 288 | 'description' => 'The browser language', | |
| 289 | 'type' => 'varchar', | |
| 290 | 'length' => 20, | |
| 291 | 'not null' => FALSE, | |
| 292 | 'default' => NULL, | |
| 293 | ], | |
| 294 | 'location_ip' => [ | |
| 295 | 'description' => 'The IP address', | |
| 296 | 'type' => 'varchar', | |
| 297 | 'length' => 45, | |
| 298 | 'not null' => TRUE, | |
| 299 | 'default' => '', | |
| 300 | ], | |
| 301 | 'location_continent' => [ | |
| 302 | 'description' => 'The continent of the visitor', | |
| 303 | 'type' => 'varchar', | |
| 304 | 'length' => 2, | |
| 305 | 'not null' => FALSE, | |
| 306 | 'default' => '', | |
| 307 | ], | |
| 308 | 'location_country' => [ | |
| 309 | 'description' => 'The country of the visitor', | |
| 310 | 'type' => 'varchar', | |
| 311 | 'length' => 2, | |
| 312 | 'not null' => FALSE, | |
| 313 | 'default' => '', | |
| 314 | ], | |
| 315 | 'location_region' => [ | |
| 316 | 'description' => 'The region of the visitor', | |
| 317 | 'type' => 'varchar', | |
| 318 | 'length' => 128, | |
| 319 | 'not null' => FALSE, | |
| 320 | 'default' => '', | |
| 321 | ], | |
| 322 | 'location_city' => [ | |
| 323 | 'description' => 'The city of the visitor', | |
| 324 | 'type' => 'varchar', | |
| 325 | 'length' => 128, | |
| 326 | 'not null' => FALSE, | |
| 327 | 'default' => '', | |
| 328 | ], | |
| 329 | 'location_latitude' => [ | |
| 330 | 'description' => 'The latitude from the IP address', | |
| 331 | 'type' => 'numeric', | |
| 332 | 'precision' => 13, | |
| 333 | 'scale' => 10, | |
| 334 | 'default' => NULL, | |
| 335 | ], | |
| 336 | 'location_longitude' => [ | |
| 337 | 'description' => 'The longitude from the IP address', | |
| 338 | 'type' => 'numeric', | |
| 339 | 'precision' => 13, | |
| 340 | 'scale' => 10, | |
| 341 | 'default' => NULL, | |
| 342 | ], | |
| 343 | 'referer_keyword' => [ | |
| 344 | 'description' => 'The referer keyword', | |
| 345 | 'type' => 'varchar', | |
| 346 | 'length' => 255, | |
| 347 | 'not null' => FALSE, | |
| 348 | 'default' => NULL, | |
| 349 | ], | |
| 350 | 'referer_name' => [ | |
| 351 | 'description' => 'The referer name', | |
| 352 | 'type' => 'varchar', | |
| 353 | 'length' => 255, | |
| 354 | 'not null' => FALSE, | |
| 355 | 'default' => NULL, | |
| 356 | ], | |
| 357 | 'referer_type' => [ | |
| 358 | 'description' => 'The referer type', | |
| 359 | 'type' => 'varchar', | |
| 360 | 'length' => 32, | |
| 361 | 'not null' => FALSE, | |
| 362 | 'default' => NULL, | |
| 363 | ], | |
| 364 | 'referer_url' => [ | |
| 365 | 'description' => 'The referer URL', | |
| 366 | 'type' => 'varchar', | |
| 367 | 'length' => 1500, | |
| 368 | 'not null' => FALSE, | |
| 369 | 'default' => NULL, | |
| 370 | ], | |
| 371 | 'campaign_source' => [ | |
| 372 | 'description' => 'The campaign source', | |
| 373 | 'type' => 'varchar', | |
| 374 | 'length' => 255, | |
| 375 | 'not null' => FALSE, | |
| 376 | 'default' => NULL, | |
| 377 | ], | |
| 378 | 'campaign_medium' => [ | |
| 379 | 'description' => 'The campaign medium', | |
| 380 | 'type' => 'varchar', | |
| 381 | 'length' => 255, | |
| 382 | 'not null' => FALSE, | |
| 383 | 'default' => NULL, | |
| 384 | ], | |
| 385 | 'campaign_content' => [ | |
| 386 | 'description' => 'The campaign content', | |
| 387 | 'type' => 'varchar', | |
| 388 | 'length' => 255, | |
| 389 | 'not null' => FALSE, | |
| 390 | 'default' => NULL, | |
| 391 | ], | |
| 392 | 'campaign_id' => [ | |
| 393 | 'description' => 'The campaign id', | |
| 394 | 'type' => 'varchar', | |
| 395 | 'length' => 255, | |
| 396 | 'not null' => FALSE, | |
| 397 | 'default' => NULL, | |
| 398 | ], | |
| 399 | 'campaign_group' => [ | |
| 400 | 'description' => 'The campaign group', | |
| 401 | 'type' => 'varchar', | |
| 402 | 'length' => 255, | |
| 403 | 'not null' => FALSE, | |
| 404 | 'default' => NULL, | |
| 405 | ], | |
| 406 | 'campaign_placement' => [ | |
| 407 | 'description' => 'The campaign placement', | |
| 408 | 'type' => 'varchar', | |
| 409 | 'length' => 255, | |
| 410 | 'not null' => FALSE, | |
| 411 | 'default' => NULL, | |
| 412 | ], | |
| 413 | ], | |
| 414 | 'primary key' => ['id'], | |
| 415 | 'indexes' => [ | |
| 416 | 'visitor_id' => ['visitor_id'], | |
| 417 | 'bot' => ['bot'], | |
| 418 | 'exit_time' => ['exit_time'], | |
| 419 | 'uid' => ['uid'], | |
| 420 | ], | |
| 421 | ]; | |
| 422 | ||
| 423 | 27 | $schema['visitors_event'] = [ |
| 424 | 27 | 'fields' => [ |
| 425 | 27 | 'id' => [ |
| 426 | 27 | 'description' => 'Primary key', |
| 427 | 27 | 'type' => 'serial', |
| 428 | 27 | 'not null' => TRUE, |
| 429 | 27 | ], |
| 430 | 27 | 'visit_id' => [ |
| 431 | 27 | 'description' => 'The visitors_visit id', |
| 432 | 27 | 'type' => 'int', |
| 433 | 27 | ], |
| 434 | 27 | 'page_view' => [ |
| 435 | 27 | 'description' => 'The unique page view id', |
| 436 | 27 | 'type' => 'varchar', |
| 437 | 27 | 'length' => 32, |
| 438 | 27 | 'not null' => FALSE, |
| 439 | 27 | 'default' => NULL, |
| 440 | 27 | ], |
| 441 | 27 | 'plugin' => [ |
| 442 | 27 | 'description' => 'The plugin that generated the event', |
| 443 | 27 | 'type' => 'varchar', |
| 444 | 27 | 'length' => 255, |
| 445 | 27 | 'not null' => FALSE, |
| 446 | 27 | 'default' => NULL, |
| 447 | 27 | ], |
| 448 | 27 | 'event' => [ |
| 449 | 27 | 'description' => 'The event', |
| 450 | 27 | 'type' => 'varchar', |
| 451 | 27 | 'length' => 255, |
| 452 | 27 | 'not null' => FALSE, |
| 453 | 27 | 'default' => NULL, |
| 454 | 27 | ], |
| 455 | 27 | 'plugin_int_1' => [ |
| 456 | 27 | 'description' => 'The first event int variable', |
| 457 | 27 | 'type' => 'int', |
| 458 | 27 | 'not null' => FALSE, |
| 459 | 27 | 'default' => NULL, |
| 460 | 27 | ], |
| 461 | 27 | 'plugin_int_2' => [ |
| 462 | 27 | 'description' => 'The second event int variable', |
| 463 | 27 | 'type' => 'int', |
| 464 | 27 | 'not null' => FALSE, |
| 465 | 27 | 'default' => NULL, |
| 466 | 27 | ], |
| 467 | 27 | 'plugin_var_1' => [ |
| 468 | 27 | 'description' => 'The first event varchar variable', |
| 469 | 27 | 'type' => 'varchar', |
| 470 | 27 | 'length' => 255, |
| 471 | 27 | 'not null' => FALSE, |
| 472 | 27 | 'default' => NULL, |
| 473 | 27 | ], |
| 474 | 27 | 'plugin_var_2' => [ |
| 475 | 27 | 'description' => 'The second event varchar variable', |
| 476 | 27 | 'type' => 'varchar', |
| 477 | 27 | 'length' => 255, |
| 478 | 27 | 'not null' => FALSE, |
| 479 | 27 | 'default' => NULL, |
| 480 | 27 | ], |
| 481 | 27 | 'plugin_var_3' => [ |
| 482 | 27 | 'description' => 'The third event varchar variable', |
| 483 | 27 | 'type' => 'varchar', |
| 484 | 27 | 'length' => 255, |
| 485 | 27 | 'not null' => FALSE, |
| 486 | 27 | 'default' => NULL, |
| 487 | 27 | ], |
| 488 | 27 | 'plugin_var_4' => [ |
| 489 | 27 | 'description' => 'The fourth event varchar variable', |
| 490 | 27 | 'type' => 'varchar', |
| 491 | 27 | 'length' => 255, |
| 492 | 27 | 'not null' => FALSE, |
| 493 | 27 | 'default' => NULL, |
| 494 | 27 | ], |
| 495 | 27 | 'event_category' => [ |
| 496 | 27 | 'description' => 'The Matomo event category', |
| 497 | 27 | 'type' => 'varchar', |
| 498 | 27 | 'length' => 255, |
| 499 | 27 | 'not null' => FALSE, |
| 500 | 27 | 'default' => NULL, |
| 501 | 27 | ], |
| 502 | 27 | 'event_action' => [ |
| 503 | 27 | 'description' => 'The Matomo event action', |
| 504 | 27 | 'type' => 'varchar', |
| 505 | 27 | 'length' => 255, |
| 506 | 27 | 'not null' => FALSE, |
| 507 | 27 | 'default' => NULL, |
| 508 | 27 | ], |
| 509 | 27 | 'event_name' => [ |
| 510 | 27 | 'description' => 'The Matomo event name', |
| 511 | 27 | 'type' => 'varchar', |
| 512 | 27 | 'length' => 255, |
| 513 | 27 | 'not null' => FALSE, |
| 514 | 27 | 'default' => NULL, |
| 515 | 27 | ], |
| 516 | 27 | 'event_value' => [ |
| 517 | 27 | 'description' => 'The Matomo event value', |
| 518 | 27 | 'type' => 'float', |
| 519 | 27 | 'size' => 'big', |
| 520 | 27 | 'not null' => FALSE, |
| 521 | 27 | 'default' => NULL, |
| 522 | 27 | ], |
| 523 | 27 | 'title' => [ |
| 524 | 27 | 'description' => 'The page title', |
| 525 | 27 | 'type' => 'text', |
| 526 | 27 | 'not null' => TRUE, |
| 527 | 27 | ], |
| 528 | 27 | 'uid' => [ |
| 529 | 27 | 'description' => 'The user who viewed the page', |
| 530 | 27 | 'type' => 'varchar', |
| 531 | 27 | 'length' => 32, |
| 532 | 27 | 'not null' => FALSE, |
| 533 | 27 | ], |
| 534 | 27 | 'url_prefix' => [ |
| 535 | 27 | 'description' => 'The protocol and if started with www', |
| 536 | 27 | 'type' => 'int', |
| 537 | 27 | 'size' => 'small', |
| 538 | 27 | ], |
| 539 | 27 | 'url' => [ |
| 540 | 27 | 'description' => 'The page URL', |
| 541 | 27 | 'type' => 'text', |
| 542 | 27 | 'not null' => TRUE, |
| 543 | 27 | ], |
| 544 | 27 | 'path' => [ |
| 545 | 27 | 'description' => 'The Drupal path', |
| 546 | 27 | 'type' => 'varchar', |
| 547 | 27 | 'length' => 255, |
| 548 | 27 | 'not null' => TRUE, |
| 549 | 27 | 'default' => '', |
| 550 | 27 | ], |
| 551 | 27 | 'route' => [ |
| 552 | 27 | 'description' => 'The Drupal route name', |
| 553 | 27 | 'type' => 'varchar', |
| 554 | 27 | 'length' => 255, |
| 555 | 27 | 'not null' => TRUE, |
| 556 | 27 | 'default' => '', |
| 557 | 27 | ], |
| 558 | 27 | 'referrer_url' => [ |
| 559 | 27 | 'description' => 'The referrer URL, without the protocol or www.', |
| 560 | 27 | 'type' => 'text', |
| 561 | 27 | 'not null' => TRUE, |
| 562 | 27 | ], |
| 563 | 27 | 'referrer_url_prefix' => [ |
| 564 | 27 | 'description' => 'The protocol and whether the referrer started with www.', |
| 565 | 27 | 'type' => 'int', |
| 566 | 27 | 'size' => 'small', |
| 567 | 27 | 'not null' => FALSE, |
| 568 | 27 | 'default' => NULL, |
| 569 | 27 | ], |
| 570 | 27 | 'referrer_internal' => [ |
| 571 | 27 | 'description' => 'Whether the referrer host matches the page host.', |
| 572 | 27 | 'type' => 'int', |
| 573 | 27 | 'size' => 'tiny', |
| 574 | 27 | 'not null' => TRUE, |
| 575 | 27 | 'default' => 0, |
| 576 | 27 | ], |
| 577 | 27 | 'referrer_path' => [ |
| 578 | 27 | 'description' => 'The Drupal path of an internal referrer.', |
| 579 | 27 | 'type' => 'varchar', |
| 580 | 27 | 'length' => 255, |
| 581 | 27 | 'not null' => TRUE, |
| 582 | 27 | 'default' => '', |
| 583 | 27 | ], |
| 584 | 27 | 'referrer_route' => [ |
| 585 | 27 | 'description' => 'The Drupal route of an internal referrer.', |
| 586 | 27 | 'type' => 'varchar', |
| 587 | 27 | 'length' => 255, |
| 588 | 27 | 'not null' => TRUE, |
| 589 | 27 | 'default' => '', |
| 590 | 27 | ], |
| 591 | 27 | 'server' => [ |
| 592 | 27 | 'description' => 'The server that generated the response', |
| 593 | 27 | 'type' => 'varchar', |
| 594 | 27 | 'length' => 255, |
| 595 | 27 | 'not null' => FALSE, |
| 596 | 27 | 'default' => NULL, |
| 597 | 27 | ], |
| 598 | 27 | 'pf_network' => [ |
| 599 | 27 | 'description' => 'Network performance', |
| 600 | 27 | 'type' => 'int', |
| 601 | 27 | 'not null' => FALSE, |
| 602 | 27 | 'default' => NULL, |
| 603 | 27 | ], |
| 604 | 27 | 'pf_server' => [ |
| 605 | 27 | 'description' => 'Server performance', |
| 606 | 27 | 'type' => 'int', |
| 607 | 27 | 'not null' => FALSE, |
| 608 | 27 | 'default' => NULL, |
| 609 | 27 | ], |
| 610 | 27 | 'pf_transfer' => [ |
| 611 | 27 | 'description' => 'Transfer performance', |
| 612 | 27 | 'type' => 'int', |
| 613 | 27 | 'not null' => FALSE, |
| 614 | 27 | 'default' => NULL, |
| 615 | 27 | ], |
| 616 | 27 | 'pf_dom_processing' => [ |
| 617 | 27 | 'description' => 'DOM processing performance', |
| 618 | 27 | 'type' => 'int', |
| 619 | 27 | 'not null' => FALSE, |
| 620 | 27 | 'default' => NULL, |
| 621 | 27 | ], |
| 622 | 27 | 'pf_dom_complete' => [ |
| 623 | 27 | 'description' => 'DOM complete performance', |
| 624 | 27 | 'type' => 'int', |
| 625 | 27 | 'not null' => FALSE, |
| 626 | 27 | 'default' => NULL, |
| 627 | 27 | ], |
| 628 | 27 | 'pf_on_load' => [ |
| 629 | 27 | 'description' => 'On load performance', |
| 630 | 27 | 'type' => 'int', |
| 631 | 27 | 'not null' => FALSE, |
| 632 | 27 | 'default' => NULL, |
| 633 | 27 | ], |
| 634 | 27 | 'pf_total' => [ |
| 635 | 27 | 'description' => 'Total performance', |
| 636 | 27 | 'type' => 'int', |
| 637 | 27 | 'not null' => FALSE, |
| 638 | 27 | 'default' => NULL, |
| 639 | 27 | ], |
| 640 | 27 | 'created' => [ |
| 641 | 27 | 'description' => 'The time the request was made', |
| 642 | 27 | 'type' => 'int', |
| 643 | 27 | ], |
| 644 | 27 | 'time_spent' => [ |
| 645 | 27 | 'description' => 'Seconds on this page, or until the next event.', |
| 646 | 27 | 'type' => 'int', |
| 647 | 27 | 'unsigned' => TRUE, |
| 648 | 27 | 'not null' => TRUE, |
| 649 | 27 | 'default' => 0, |
| 650 | 27 | ], |
| 651 | 27 | ], |
| 652 | 27 | 'primary key' => ['id'], |
| 653 | 27 | 'indexes' => [ |
| 654 | 27 | 'visit_id' => ['visit_id'], |
| 655 | 27 | 'created' => ['created'], |
| 656 | 27 | ], |
| 657 | 27 | ]; |
| 658 | ||
| 659 | 27 | $schema['visitors_media'] = visitors_media_schema(); |
| 660 | ||
| 661 | 27 | $schema['visitors_counter'] = [ |
| 662 | 27 | 'fields' => [ |
| 663 | 27 | 'entity_id' => [ |
| 664 | 27 | 'description' => 'The entity id for these visits.', |
| 665 | 27 | 'type' => 'int', |
| 666 | 27 | 'unsigned' => TRUE, |
| 667 | 27 | 'not null' => TRUE, |
| 668 | 27 | 'default' => 0, |
| 669 | 27 | ], |
| 670 | 27 | 'entity_type' => [ |
| 671 | 27 | 'type' => 'varchar_ascii', |
| 672 | 27 | 'not null' => TRUE, |
| 673 | 27 | 'default' => 'node', |
| 674 | 27 | 'length' => EntityTypeInterface::ID_MAX_LENGTH, |
| 675 | 27 | 'description' => 'The entity_type of the entity for these visits.', |
| 676 | 27 | ], |
| 677 | 27 | 'total' => [ |
| 678 | 27 | 'description' => 'The total number of times the entity has been viewed.', |
| 679 | 27 | 'type' => 'int', |
| 680 | 27 | 'unsigned' => TRUE, |
| 681 | 27 | 'not null' => TRUE, |
| 682 | 27 | 'default' => 0, |
| 683 | 27 | 'size' => 'big', |
| 684 | 27 | ], |
| 685 | 27 | 'today' => [ |
| 686 | 27 | 'description' => 'The total number of times the entity has been viewed today.', |
| 687 | 27 | 'type' => 'int', |
| 688 | 27 | 'unsigned' => TRUE, |
| 689 | 27 | 'not null' => TRUE, |
| 690 | 27 | 'default' => 0, |
| 691 | 27 | 'size' => 'medium', |
| 692 | 27 | ], |
| 693 | 27 | 'timestamp' => [ |
| 694 | 27 | 'description' => 'The most recent time the entity has been viewed.', |
| 695 | 27 | 'type' => 'int', |
| 696 | 27 | 'unsigned' => TRUE, |
| 697 | 27 | 'not null' => TRUE, |
| 698 | 27 | 'default' => 0, |
| 699 | 27 | ], |
| 700 | 27 | ], |
| 701 | 27 | 'primary key' => ['entity_type', 'entity_id'], |
| 702 | 27 | ]; |
| 703 | ||
| 704 | 27 | return $schema; |
| 705 | } | |
| 706 | ||
| 707 | /** | |
| 708 | * Implements hook_requirements(). | |
| 709 | */ | |
| 710 | function visitors_requirements($phase) { | |
| 711 | 3 | $requirements = []; |
| 712 | 3 | if ($phase != 'runtime') { |
| 713 | 1 | return $requirements; |
| 714 | } | |
| 715 | 2 | $device = \Drupal::service('visitors.device'); |
| 716 | 2 | if (!$device->hasLibrary()) { |
| 717 | 1 | $requirements['visitors_device'] = [ |
| 718 | 1 | 'title' => t('Device Detector'), |
| 719 | 1 | 'value' => t('Not found'), |
| 720 | 1 | 'severity' => DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.2.0', fn() => RequirementSeverity::Warning, fn() => REQUIREMENT_WARNING), |
| 721 | 1 | 'description' => t('The <a href=":url">Device Detector</a> library is strongly encouraged by the Visitors module. Composer will download the library automatically.', [ |
| 722 | 1 | ':url' => 'https://github.com/matomo-org/device-detector', |
| 723 | 1 | ]), |
| 724 | 1 | ]; |
| 725 | } | |
| 726 | ||
| 727 | 2 | return $requirements; |
| 728 | } | |
| 729 | ||
| 730 | /** | |
| 731 | * Upgrade to Visitors 3. | |
| 732 | */ | |
| 733 | function visitors_update_30000(&$sandbox) { | |
| 734 | ||
| 735 | 8 | if (!isset($sandbox['current'])) { |
| 736 | 6 | $sandbox['current'] = 0; |
| 737 | 6 | $sandbox['max'] = 5; |
| 738 | } | |
| 739 | ||
| 740 | // Change visitors.settings to visitors.settings. | |
| 741 | 8 | if ($sandbox['current'] == 0) { |
| 742 | 6 | $config_factory = \Drupal::configFactory(); |
| 743 | ||
| 744 | 6 | $config = $config_factory->getEditable('visitors.config'); |
| 745 | 6 | $config_data = $config->getRawData(); |
| 746 | ||
| 747 | 6 | $settings = $config_factory->getEditable('visitors.settings'); |
| 748 | 6 | $settings->setData($config_data)->save(); |
| 749 | ||
| 750 | 6 | $config->delete(); |
| 751 | } | |
| 752 | ||
| 753 | 8 | if ($sandbox['current'] == 1) { |
| 754 | 5 | $schema = \Drupal::database()->schema(); |
| 755 | // @todo replace visitors_schema() with static before an initial release. | |
| 756 | 5 | $visitors_schema = visitors_schema(); |
| 757 | 5 | $schema->createTable('visitors_visit', $visitors_schema['visitors_visit']); |
| 758 | 5 | $schema->createTable('visitors_event', $visitors_schema['visitors_event']); |
| 759 | } | |
| 760 | ||
| 761 | 8 | if ($sandbox['current'] == 2) { |
| 762 | 6 | $config_factory = \Drupal::configFactory(); |
| 763 | ||
| 764 | // @todo This needs to be replace with static before an initial release. | |
| 765 | 6 | $view = file_get_contents(__DIR__ . '/config/optional/views.view.visitors.yml'); |
| 766 | 6 | $config_data = Yaml::decode($view); |
| 767 | 6 | $config_factory->getEditable('views.view.visitors')->setData($config_data)->save(); |
| 768 | ||
| 769 | // @todo This needs to be replace with static before an initial release. | |
| 770 | 6 | $spam = file_get_contents(__DIR__ . '/config/install/visitors.spam.yml'); |
| 771 | 6 | $config_data = Yaml::decode($spam); |
| 772 | 6 | $config_factory->getEditable('visitors.spam')->setData($config_data)->save(); |
| 773 | ||
| 774 | // @todo This needs to be replace with static before an initial release. | |
| 775 | 6 | $ai_assistants = file_get_contents(__DIR__ . '/config/install/visitors.ai_assistants.yml'); |
| 776 | 6 | $config_data = Yaml::decode($ai_assistants); |
| 777 | 6 | $config_factory->getEditable('visitors.ai_assistants')->setData($config_data)->save(); |
| 778 | ||
| 779 | // @todo This needs to be replace with static before an initial release. | |
| 780 | 6 | $search_engine = file_get_contents(__DIR__ . '/config/install/visitors.search_engines.yml'); |
| 781 | 6 | $config_data = Yaml::decode($search_engine); |
| 782 | 6 | $config_factory->getEditable('visitors.search_engine')->setData($config_data)->save(); |
| 783 | ||
| 784 | // @todo This needs to be replace with static before an initial release. | |
| 785 | 6 | $social_networks = file_get_contents(__DIR__ . '/config/install/visitors.social_networks.yml'); |
| 786 | 6 | $config_data = Yaml::decode($social_networks); |
| 787 | 6 | $config_factory->getEditable('visitors.social_networks')->setData($config_data)->save(); |
| 788 | ||
| 789 | // Check if views 'views.view.visitors_geoip' exists, and delete it. | |
| 790 | 6 | $geoip_view = $config_factory->getEditable('views.view.visitors_geoip'); |
| 791 | 6 | if ($geoip_view) { |
| 792 | 6 | $geoip_view->delete(); |
| 793 | } | |
| 794 | ||
| 795 | } | |
| 796 | ||
| 797 | 8 | if ($sandbox['current'] == 3) { |
| 798 | 5 | $visitors_geoip_is_installed = \Drupal::moduleHandler()->moduleExists('visitors_geoip'); |
| 799 | 5 | if ($visitors_geoip_is_installed) { |
| 800 | 1 | \Drupal::service('module_installer')->uninstall(['visitors_geoip']); |
| 801 | } | |
| 802 | } | |
| 803 | ||
| 804 | 8 | if ($sandbox['current'] == 4) { |
| 805 | // Migrate existing visibility settings to condition-based system. | |
| 806 | 6 | $config_factory = \Drupal::configFactory(); |
| 807 | 6 | $settings = $config_factory->getEditable('visitors.settings'); |
| 808 | ||
| 809 | 6 | $tracking_conditions = []; |
| 810 | ||
| 811 | // Migrate request path visibility settings. | |
| 812 | 6 | $request_path_pages = $settings->get('visibility.request_path_pages') ?: ''; |
| 813 | 6 | $request_path_mode = $settings->get('visibility.request_path_mode') ?: 0; |
| 814 | ||
| 815 | 6 | if (!empty($request_path_pages)) { |
| 816 | 0 | $tracking_conditions['request_path'] = [ |
| 817 | 0 | 'id' => 'request_path', |
| 818 | 0 | 'pages' => $request_path_pages, |
| 819 | // Legacy mode 0 = exclude, mode 1 = include. | |
| 820 | 0 | 'negate' => $request_path_mode === 0, |
| 821 | 0 | ]; |
| 822 | } | |
| 823 | ||
| 824 | // Migrate user role visibility settings. | |
| 825 | 6 | $user_role_roles = $settings->get('visibility.user_role_roles') ?: []; |
| 826 | 6 | $user_role_mode = $settings->get('visibility.user_role_mode') ?: 0; |
| 827 | ||
| 828 | 6 | if (!empty($user_role_roles)) { |
| 829 | 0 | $tracking_conditions['user_role'] = [ |
| 830 | 0 | 'id' => 'user_role', |
| 831 | 0 | 'roles' => $user_role_roles, |
| 832 | // Legacy mode 0 = exclude, mode 1 = include. | |
| 833 | 0 | 'negate' => $user_role_mode === 0, |
| 834 | 0 | ]; |
| 835 | } | |
| 836 | ||
| 837 | // Add exclude user 1 condition if configured. | |
| 838 | 6 | if ($settings->get('visibility.exclude_user1')) { |
| 839 | 0 | $tracking_conditions['exclude_admin'] = [ |
| 840 | 0 | 'id' => 'user_role', |
| 841 | 0 | 'roles' => ['administrator'], |
| 842 | 0 | 'negate' => TRUE, |
| 843 | 0 | ]; |
| 844 | } | |
| 845 | ||
| 846 | // Save new condition-based configuration. | |
| 847 | 6 | if (!empty($tracking_conditions)) { |
| 848 | 0 | $settings->set('tracking_conditions', $tracking_conditions); |
| 849 | } | |
| 850 | ||
| 851 | // Remove old visibility configuration. | |
| 852 | 6 | $settings->clear('visibility.request_path_mode') |
| 853 | 6 | ->clear('visibility.request_path_pages') |
| 854 | 6 | ->clear('visibility.user_role_mode') |
| 855 | 6 | ->clear('visibility.user_role_roles') |
| 856 | 6 | ->clear('visibility.exclude_user1') |
| 857 | 6 | ->save(); |
| 858 | } | |
| 859 | ||
| 860 | 8 | $sandbox['current'] += 1; |
| 861 | ||
| 862 | 8 | $sandbox['#finished'] = ($sandbox['max'] == $sandbox['current']) ? 1 : $sandbox['current'] / $sandbox['max']; |
| 863 | } | |
| 864 | ||
| 865 | /** | |
| 866 | * Adds the client debug setting. | |
| 867 | */ | |
| 868 | function visitors_update_30001() { | |
| 869 | 1 | $config = \Drupal::configFactory()->getEditable('visitors.settings'); |
| 870 | 1 | if ($config->get('client_debug') === NULL) { |
| 871 | 1 | $config->set('client_debug', FALSE)->save(); |
| 872 | } | |
| 873 | } | |
| 874 | ||
| 875 | /** | |
| 876 | * Upgrades legacy 3.0.0-alpha database schemas. | |
| 877 | * | |
| 878 | * Alpha releases changed the schema without update hooks. The installed | |
| 879 | * schema version stayed at 30000, so later releases could not alter the | |
| 880 | * tables. Inspect the tables to see which alpha created them. | |
| 881 | * | |
| 882 | * Field specs are copied here so later edits to hook_schema() do not | |
| 883 | * change this upgrade. | |
| 884 | * | |
| 885 | * @return \Drupal\Core\StringTranslation\TranslatableMarkup | |
| 886 | * A message naming the detected release. | |
| 887 | */ | |
| 888 | function visitors_update_30002(): TranslatableMarkup { | |
| 889 | 4 | $schema = \Drupal::database()->schema(); |
| 890 | 4 | if ($schema->tableExists('visitors_action')) { |
| 891 | 1 | $version = '3.0.0-alpha1'; |
| 892 | } | |
| 893 | 4 | elseif (!$schema->fieldExists('visitors_visit', 'referer_url')) { |
| 894 | 1 | $version = '3.0.0-alpha2'; |
| 895 | } | |
| 896 | 3 | elseif ($schema->fieldExists('visitors_visit', 'visit_count')) { |
| 897 | 1 | $version = '3.0.0-alpha3'; |
| 898 | } | |
| 899 | else { | |
| 900 | 2 | $version = 'current'; |
| 901 | } | |
| 902 | ||
| 903 | // Alpha1 stored events in visitors_action. | |
| 904 | 4 | if ($schema->tableExists('visitors_action') |
| 905 | 1 | && !$schema->tableExists('visitors_event')) { |
| 906 | 1 | $schema->renameTable('visitors_action', 'visitors_event'); |
| 907 | } | |
| 908 | 4 | if ($schema->tableExists('visitors_event') |
| 909 | 4 | && $schema->fieldExists('visitors_event', 'action') |
| 910 | 1 | && !$schema->fieldExists('visitors_event', 'event')) { |
| 911 | 1 | $schema->changeField('visitors_event', 'action', 'event', [ |
| 912 | 1 | 'description' => 'The event', |
| 913 | 1 | 'type' => 'varchar', |
| 914 | 1 | 'length' => 255, |
| 915 | 1 | 'not null' => FALSE, |
| 916 | 1 | 'default' => NULL, |
| 917 | 1 | ]); |
| 918 | } | |
| 919 | ||
| 920 | // Alpha2 had no referer columns. | |
| 921 | $referer_fields = [ | |
| 922 | 'referer_keyword' => [ | |
| 923 | 'description' => 'The referer keyword', | |
| 924 | 'type' => 'varchar', | |
| 925 | 'length' => 255, | |
| 926 | 'not null' => FALSE, | |
| 927 | 'default' => NULL, | |
| 928 | ], | |
| 929 | 'referer_name' => [ | |
| 930 | 'description' => 'The referer name', | |
| 931 | 'type' => 'varchar', | |
| 932 | 'length' => 255, | |
| 933 | 'not null' => FALSE, | |
| 934 | 'default' => NULL, | |
| 935 | ], | |
| 936 | 'referer_type' => [ | |
| 937 | 'description' => 'The referer type', | |
| 938 | 'type' => 'varchar', | |
| 939 | 'length' => 32, | |
| 940 | 'not null' => FALSE, | |
| 941 | 'default' => NULL, | |
| 942 | ], | |
| 943 | 'referer_url' => [ | |
| 944 | 'description' => 'The referer URL', | |
| 945 | 'type' => 'varchar', | |
| 946 | 'length' => 1500, | |
| 947 | 'not null' => FALSE, | |
| 948 | 'default' => NULL, | |
| 949 | ], | |
| 950 | ]; | |
| 951 | 4 | foreach ($referer_fields as $field => $spec) { |
| 952 | 4 | if (!$schema->fieldExists('visitors_visit', $field)) { |
| 953 | 2 | $schema->addField('visitors_visit', $field, $spec); |
| 954 | } | |
| 955 | } | |
| 956 | ||
| 957 | // Alpha3 used visit_count and page_count. NULLs cannot move into the | |
| 958 | // NOT NULL replacements, so store 0 first and keep the old values. | |
| 959 | $count_renames = [ | |
| 960 | 'visit_count' => [ | |
| 961 | 'field' => 'total_visits', | |
| 962 | 'spec' => [ | |
| 963 | 'description' => 'Total visits', | |
| 964 | 'type' => 'int', | |
| 965 | 'not null' => TRUE, | |
| 966 | 'default' => 0, | |
| 967 | ], | |
| 968 | ], | |
| 969 | 'page_count' => [ | |
| 970 | 'field' => 'total_page_views', | |
| 971 | 'spec' => [ | |
| 972 | 'description' => 'Total page views this visit', | |
| 973 | 'type' => 'int', | |
| 974 | 'not null' => TRUE, | |
| 975 | 'default' => 0, | |
| 976 | ], | |
| 977 | ], | |
| 978 | ]; | |
| 979 | 4 | foreach ($count_renames as $old_field => $replacement) { |
| 980 | 4 | $new_field = $replacement['field']; |
| 981 | 4 | if ($schema->fieldExists('visitors_visit', $old_field)) { |
| 982 | 3 | \Drupal::database()->update('visitors_visit') |
| 983 | 3 | ->fields([$old_field => 0]) |
| 984 | 3 | ->isNull($old_field) |
| 985 | 3 | ->execute(); |
| 986 | 3 | $schema->changeField( |
| 987 | 3 | 'visitors_visit', |
| 988 | 3 | $old_field, |
| 989 | 3 | $new_field, |
| 990 | 3 | $replacement['spec'], |
| 991 | 3 | ); |
| 992 | } | |
| 993 | 2 | elseif (!$schema->fieldExists('visitors_visit', $new_field)) { |
| 994 | 0 | $schema->addField('visitors_visit', $new_field, $replacement['spec']); |
| 995 | } | |
| 996 | } | |
| 997 | ||
| 998 | $added_fields = [ | |
| 999 | 'total_events' => [ | |
| 1000 | 'description' => 'Total events this visit', | |
| 1001 | 'type' => 'int', | |
| 1002 | 'not null' => TRUE, | |
| 1003 | 'default' => 0, | |
| 1004 | ], | |
| 1005 | 'time_since_first' => [ | |
| 1006 | 'description' => 'Seconds since the visitor\'s first visit', | |
| 1007 | 'type' => 'int', | |
| 1008 | 'not null' => FALSE, | |
| 1009 | 'default' => NULL, | |
| 1010 | ], | |
| 1011 | 'time_since_last' => [ | |
| 1012 | 'description' => 'Seconds since the visitor\'s last visit', | |
| 1013 | 'type' => 'int', | |
| 1014 | 'not null' => FALSE, | |
| 1015 | 'default' => NULL, | |
| 1016 | ], | |
| 1017 | ]; | |
| 1018 | 4 | foreach ($added_fields as $field => $spec) { |
| 1019 | 4 | if (!$schema->fieldExists('visitors_visit', $field)) { |
| 1020 | 3 | $schema->addField('visitors_visit', $field, $spec); |
| 1021 | } | |
| 1022 | } | |
| 1023 | ||
| 1024 | 4 | if ($version === 'current') { |
| 1025 | 2 | return t('Visitors schema is already current.'); |
| 1026 | } | |
| 1027 | 3 | return t('Upgraded Visitors schema from @version.', [ |
| 1028 | 3 | '@version' => $version, |
| 1029 | 3 | ]); |
| 1030 | } | |
| 1031 | ||
| 1032 | /** | |
| 1033 | * Adds Matomo trackEvent columns to {visitors_event}. | |
| 1034 | * | |
| 1035 | * Field specs are copied here so later edits to hook_schema() do not | |
| 1036 | * change this upgrade. | |
| 1037 | */ | |
| 1038 | function visitors_update_30003(): void { | |
| 1039 | 1 | $schema = \Drupal::database()->schema(); |
| 1040 | $fields = [ | |
| 1041 | 'event_category' => [ | |
| 1042 | 'description' => 'The Matomo event category', | |
| 1043 | 'type' => 'varchar', | |
| 1044 | 'length' => 255, | |
| 1045 | 'not null' => FALSE, | |
| 1046 | 'default' => NULL, | |
| 1047 | ], | |
| 1048 | 'event_action' => [ | |
| 1049 | 'description' => 'The Matomo event action', | |
| 1050 | 'type' => 'varchar', | |
| 1051 | 'length' => 255, | |
| 1052 | 'not null' => FALSE, | |
| 1053 | 'default' => NULL, | |
| 1054 | ], | |
| 1055 | 'event_name' => [ | |
| 1056 | 'description' => 'The Matomo event name', | |
| 1057 | 'type' => 'varchar', | |
| 1058 | 'length' => 255, | |
| 1059 | 'not null' => FALSE, | |
| 1060 | 'default' => NULL, | |
| 1061 | ], | |
| 1062 | 'event_value' => [ | |
| 1063 | 'description' => 'The Matomo event value', | |
| 1064 | 'type' => 'float', | |
| 1065 | 'size' => 'big', | |
| 1066 | 'not null' => FALSE, | |
| 1067 | 'default' => NULL, | |
| 1068 | ], | |
| 1069 | ]; | |
| 1070 | 1 | foreach ($fields as $field => $spec) { |
| 1071 | 1 | if (!$schema->fieldExists('visitors_event', $field)) { |
| 1072 | 1 | $schema->addField('visitors_event', $field, $spec); |
| 1073 | } | |
| 1074 | } | |
| 1075 | } | |
| 1076 | ||
| 1077 | /** | |
| 1078 | * Stores the user id as a 32 character string. | |
| 1079 | * | |
| 1080 | * Field specs are copied here so later edits to hook_schema() do not | |
| 1081 | * change this upgrade. Existing integers are kept as decimal strings. | |
| 1082 | */ | |
| 1083 | function visitors_update_30004(): void { | |
| 1084 | 1 | $schema = \Drupal::database()->schema(); |
| 1085 | 1 | $visit_uid = [ |
| 1086 | 1 | 'description' => 'The user of the session', |
| 1087 | 1 | 'type' => 'varchar', |
| 1088 | 1 | 'length' => 32, |
| 1089 | 1 | 'not null' => FALSE, |
| 1090 | 1 | ]; |
| 1091 | 1 | $event_uid = [ |
| 1092 | 1 | 'description' => 'The user who viewed the page', |
| 1093 | 1 | 'type' => 'varchar', |
| 1094 | 1 | 'length' => 32, |
| 1095 | 1 | 'not null' => FALSE, |
| 1096 | 1 | ]; |
| 1097 | ||
| 1098 | 1 | if ($schema->fieldExists('visitors_visit', 'uid')) { |
| 1099 | 1 | if ($schema->indexExists('visitors_visit', 'uid')) { |
| 1100 | 1 | $schema->dropIndex('visitors_visit', 'uid'); |
| 1101 | } | |
| 1102 | 1 | $schema->changeField('visitors_visit', 'uid', 'uid', $visit_uid); |
| 1103 | 1 | if (!$schema->indexExists('visitors_visit', 'uid')) { |
| 1104 | 1 | $schema->addIndex('visitors_visit', 'uid', ['uid'], [ |
| 1105 | 1 | 'fields' => [ |
| 1106 | 1 | 'uid' => $visit_uid, |
| 1107 | 1 | ], |
| 1108 | 1 | ]); |
| 1109 | } | |
| 1110 | } | |
| 1111 | ||
| 1112 | 1 | if ($schema->fieldExists('visitors_event', 'uid')) { |
| 1113 | 1 | $schema->changeField('visitors_event', 'uid', 'uid', $event_uid); |
| 1114 | } | |
| 1115 | } | |
| 1116 | ||
| 1117 | /** | |
| 1118 | * There is no separate scroll depth report. | |
| 1119 | * | |
| 1120 | * Databases that already ran the first version of this update still have | |
| 1121 | * the display. The following update removes it. | |
| 1122 | */ | |
| 1123 | function visitors_update_30005(): void { | |
| 1124 | // Scroll depth is stored as events. It does not have its own report. | |
| 1125 | 0 | } |
| 1126 | ||
| 1127 | /** | |
| 1128 | * Removes the scroll depth display from the Visitors view. | |
| 1129 | */ | |
| 1130 | function visitors_update_30006(): void { | |
| 1131 | 1 | $storage = \Drupal::entityTypeManager()->getStorage('view'); |
| 1132 | /** @var \Drupal\views\Entity\View|null $view */ | |
| 1133 | 1 | $view = $storage->load('visitors'); |
| 1134 | 1 | if (!$view) { |
| 1135 | 0 | return; |
| 1136 | } | |
| 1137 | ||
| 1138 | 1 | $displays = $view->get('display'); |
| 1139 | 1 | if (!isset($displays['scroll_depth_table'])) { |
| 1140 | 0 | return; |
| 1141 | } | |
| 1142 | ||
| 1143 | 1 | unset($displays['scroll_depth_table']); |
| 1144 | 1 | $view->set('display', $displays); |
| 1145 | 1 | $view->save(); |
| 1146 | } | |
| 1147 | ||
| 1148 | /** | |
| 1149 | * Splits referrer URLs into a prefix, host, and internal path. | |
| 1150 | */ | |
| 1151 | function visitors_update_30007(&$sandbox): void { | |
| 1152 | 1 | $database = \Drupal::database(); |
| 1153 | 1 | $schema = $database->schema(); |
| 1154 | ||
| 1155 | 1 | if (!isset($sandbox['last_id'])) { |
| 1156 | 1 | $fields = visitors_schema()['visitors_event']['fields']; |
| 1157 | 1 | foreach ([ |
| 1158 | 1 | 'referrer_url_prefix', |
| 1159 | 1 | 'referrer_internal', |
| 1160 | 1 | 'referrer_path', |
| 1161 | 1 | 'referrer_route', |
| 1162 | 1 | ] as $name) { |
| 1163 | 1 | if (!$schema->fieldExists('visitors_event', $name)) { |
| 1164 | 0 | $schema->addField('visitors_event', $name, $fields[$name]); |
| 1165 | } | |
| 1166 | } | |
| 1167 | 1 | visitors_update_30007_displays(); |
| 1168 | ||
| 1169 | 1 | $sandbox['last_id'] = 0; |
| 1170 | 1 | $sandbox['progress'] = 0; |
| 1171 | 1 | $sandbox['max'] = (int) $database->select('visitors_event', 'e') |
| 1172 | 1 | ->countQuery() |
| 1173 | 1 | ->execute() |
| 1174 | 1 | ->fetchField(); |
| 1175 | } | |
| 1176 | ||
| 1177 | 1 | if ($sandbox['max'] === 0) { |
| 1178 | 0 | $sandbox['#finished'] = 1; |
| 1179 | 0 | return; |
| 1180 | } | |
| 1181 | ||
| 1182 | /** @var \Drupal\visitors\VisitorsReferrerInterface $referrer */ | |
| 1183 | 1 | $referrer = \Drupal::service('visitors.referrer'); |
| 1184 | 1 | $rows = $database->select('visitors_event', 'e') |
| 1185 | 1 | ->fields('e', ['id', 'referrer_url', 'url']) |
| 1186 | 1 | ->condition('id', $sandbox['last_id'], '>') |
| 1187 | 1 | ->orderBy('id') |
| 1188 | 1 | ->range(0, 50) |
| 1189 | 1 | ->execute(); |
| 1190 | ||
| 1191 | 1 | $count = 0; |
| 1192 | 1 | foreach ($rows as $row) { |
| 1193 | 1 | $count++; |
| 1194 | 1 | $sandbox['last_id'] = (int) $row->id; |
| 1195 | 1 | $page_host = $referrer->hostOf((string) $row->url); |
| 1196 | 1 | $database->update('visitors_event') |
| 1197 | 1 | ->fields($referrer->storageFields((string) $row->referrer_url, $page_host)) |
| 1198 | 1 | ->condition('id', $row->id) |
| 1199 | 1 | ->execute(); |
| 1200 | 1 | $sandbox['progress']++; |
| 1201 | } | |
| 1202 | ||
| 1203 | 1 | if ($count === 0) { |
| 1204 | 0 | $sandbox['#finished'] = 1; |
| 1205 | 0 | return; |
| 1206 | } | |
| 1207 | ||
| 1208 | 1 | $sandbox['#finished'] = min(0.99, $sandbox['progress'] / $sandbox['max']); |
| 1209 | 1 | if ($sandbox['progress'] >= $sandbox['max']) { |
| 1210 | 1 | $sandbox['#finished'] = 1; |
| 1211 | } | |
| 1212 | } | |
| 1213 | ||
| 1214 | /** | |
| 1215 | * Copies the referrer displays from the shipped Visitors view. | |
| 1216 | */ | |
| 1217 | function visitors_update_30007_displays(): void { | |
| 1218 | 1 | $view_yaml = file_get_contents(__DIR__ . '/config/optional/views.view.visitors.yml'); |
| 1219 | 1 | if ($view_yaml === FALSE) { |
| 1220 | 0 | return; |
| 1221 | } | |
| 1222 | 1 | $config_data = Yaml::decode($view_yaml); |
| 1223 | 1 | $storage = \Drupal::entityTypeManager()->getStorage('view'); |
| 1224 | /** @var \Drupal\views\Entity\View|null $view */ | |
| 1225 | 1 | $view = $storage->load('visitors'); |
| 1226 | 1 | if (!$view || !isset($config_data['display'])) { |
| 1227 | 0 | return; |
| 1228 | } | |
| 1229 | ||
| 1230 | 1 | $displays = $view->get('display'); |
| 1231 | 1 | foreach (['referrers_table', 'referrer_table'] as $id) { |
| 1232 | 1 | if (isset($config_data['display'][$id])) { |
| 1233 | 1 | $displays[$id] = $config_data['display'][$id]; |
| 1234 | } | |
| 1235 | } | |
| 1236 | 1 | $view->set('display', $displays); |
| 1237 | 1 | $view->save(); |
| 1238 | } | |
| 1239 | ||
| 1240 | /** | |
| 1241 | * Stores same-site visit referrers as direct entry. | |
| 1242 | */ | |
| 1243 | function visitors_update_30008(): void { | |
| 1244 | 1 | $database = \Drupal::database(); |
| 1245 | 1 | if ($database->schema()->tableExists('visitors_visit')) { |
| 1246 | 1 | $database->update('visitors_visit') |
| 1247 | 1 | ->fields(['referer_type' => 'direct']) |
| 1248 | 1 | ->condition('referer_type', 'internal') |
| 1249 | 1 | ->execute(); |
| 1250 | } | |
| 1251 | ||
| 1252 | 1 | $view_yaml = file_get_contents(__DIR__ . '/config/optional/views.view.visitors.yml'); |
| 1253 | 1 | if ($view_yaml === FALSE) { |
| 1254 | 0 | return; |
| 1255 | } | |
| 1256 | 1 | $config_data = Yaml::decode($view_yaml); |
| 1257 | 1 | $storage = \Drupal::entityTypeManager()->getStorage('view'); |
| 1258 | /** @var \Drupal\views\Entity\View|null $view */ | |
| 1259 | 1 | $view = $storage->load('visitors'); |
| 1260 | 1 | if (!$view || !isset($config_data['display'])) { |
| 1261 | 0 | return; |
| 1262 | } | |
| 1263 | ||
| 1264 | 1 | $displays = $view->get('display'); |
| 1265 | $ids = [ | |
| 1266 | 'referrer_overview_pie', | |
| 1267 | 'referrer_overview_table', | |
| 1268 | 'referrers_all_table', | |
| 1269 | 'search_engines_table', | |
| 1270 | 'search_keywords_table', | |
| 1271 | 'search_engine_keywords', | |
| 1272 | 'search_keyword_engines', | |
| 1273 | 'websites_table', | |
| 1274 | 'website_urls', | |
| 1275 | 'social_referrers_table', | |
| 1276 | 'social_urls', | |
| 1277 | 'ai_visitors_pie', | |
| 1278 | 'ai_visitors_table', | |
| 1279 | 'ai_entry_pages', | |
| 1280 | 'campaigns_table', | |
| 1281 | 'campaign_keywords', | |
| 1282 | ]; | |
| 1283 | 1 | foreach ($ids as $id) { |
| 1284 | 1 | if (isset($config_data['display'][$id])) { |
| 1285 | 1 | $displays[$id] = $config_data['display'][$id]; |
| 1286 | } | |
| 1287 | } | |
| 1288 | 1 | $view->set('display', $displays); |
| 1289 | 1 | $view->save(); |
| 1290 | } | |
| 1291 | ||
| 1292 | /** | |
| 1293 | * Adds the Downloads report. | |
| 1294 | */ | |
| 1295 | function visitors_update_30009(): void { | |
| 1296 | 0 | $view_yaml = file_get_contents(__DIR__ . '/config/optional/views.view.visitors.yml'); |
| 1297 | 0 | if ($view_yaml === FALSE) { |
| 1298 | 0 | return; |
| 1299 | } | |
| 1300 | 0 | $config_data = Yaml::decode($view_yaml); |
| 1301 | 0 | $storage = \Drupal::entityTypeManager()->getStorage('view'); |
| 1302 | /** @var \Drupal\views\Entity\View|null $view */ | |
| 1303 | 0 | $view = $storage->load('visitors'); |
| 1304 | 0 | if (!$view || !isset($config_data['display']['downloads_table'])) { |
| 1305 | 0 | return; |
| 1306 | } | |
| 1307 | ||
| 1308 | 0 | $displays = $view->get('display'); |
| 1309 | 0 | $displays['downloads_table'] = $config_data['display']['downloads_table']; |
| 1310 | 0 | $view->set('display', $displays); |
| 1311 | 0 | $view->save(); |
| 1312 | } | |
| 1313 | ||
| 1314 | /** | |
| 1315 | * Schema for one media view. | |
| 1316 | * | |
| 1317 | * A row is inserted when the media is seen and updated while it plays. | |
| 1318 | * | |
| 1319 | * @return array | |
| 1320 | * The visitors_media table definition. | |
| 1321 | */ | |
| 1322 | function visitors_media_schema(): array { | |
| 1323 | 0 | return [ |
| 1324 | 0 | 'description' => 'Audio and video viewed during a visit.', |
| 1325 | 0 | 'fields' => [ |
| 1326 | 0 | 'id' => [ |
| 1327 | 0 | 'description' => 'Primary key', |
| 1328 | 0 | 'type' => 'serial', |
| 1329 | 0 | 'not null' => TRUE, |
| 1330 | 0 | ], |
| 1331 | 0 | 'visit_id' => [ |
| 1332 | 0 | 'description' => 'The visitors_visit id', |
| 1333 | 0 | 'type' => 'int', |
| 1334 | 0 | 'not null' => TRUE, |
| 1335 | 0 | ], |
| 1336 | 0 | 'page_view' => [ |
| 1337 | 0 | 'description' => 'The unique page view id', |
| 1338 | 0 | 'type' => 'varchar', |
| 1339 | 0 | 'length' => 32, |
| 1340 | 0 | 'not null' => FALSE, |
| 1341 | 0 | 'default' => NULL, |
| 1342 | 0 | ], |
| 1343 | 0 | 'media_id' => [ |
| 1344 | 0 | 'description' => 'The id of this media view', |
| 1345 | 0 | 'type' => 'varchar', |
| 1346 | 0 | 'length' => 32, |
| 1347 | 0 | 'not null' => TRUE, |
| 1348 | 0 | ], |
| 1349 | 0 | 'resource' => [ |
| 1350 | 0 | 'description' => 'The media resource URL', |
| 1351 | 0 | 'type' => 'text', |
| 1352 | 0 | 'not null' => TRUE, |
| 1353 | 0 | ], |
| 1354 | 0 | 'media_type' => [ |
| 1355 | 0 | 'description' => 'video or audio', |
| 1356 | 0 | 'type' => 'varchar', |
| 1357 | 0 | 'length' => 16, |
| 1358 | 0 | 'not null' => TRUE, |
| 1359 | 0 | ], |
| 1360 | 0 | 'title' => [ |
| 1361 | 0 | 'description' => 'The media title', |
| 1362 | 0 | 'type' => 'varchar', |
| 1363 | 0 | 'length' => 255, |
| 1364 | 0 | 'not null' => TRUE, |
| 1365 | 0 | 'default' => '', |
| 1366 | 0 | ], |
| 1367 | 0 | 'player' => [ |
| 1368 | 0 | 'description' => 'The media player name', |
| 1369 | 0 | 'type' => 'varchar', |
| 1370 | 0 | 'length' => 32, |
| 1371 | 0 | 'not null' => TRUE, |
| 1372 | 0 | 'default' => 'html5', |
| 1373 | 0 | ], |
| 1374 | 0 | 'spent_time' => [ |
| 1375 | 0 | 'description' => 'Seconds the media was actually playing', |
| 1376 | 0 | 'type' => 'int', |
| 1377 | 0 | 'not null' => TRUE, |
| 1378 | 0 | 'default' => 0, |
| 1379 | 0 | ], |
| 1380 | 0 | 'length' => [ |
| 1381 | 0 | 'description' => 'The media duration in seconds', |
| 1382 | 0 | 'type' => 'int', |
| 1383 | 0 | 'not null' => FALSE, |
| 1384 | 0 | 'default' => NULL, |
| 1385 | 0 | ], |
| 1386 | 0 | 'progress' => [ |
| 1387 | 0 | 'description' => 'The furthest position reached, in seconds', |
| 1388 | 0 | 'type' => 'int', |
| 1389 | 0 | 'not null' => FALSE, |
| 1390 | 0 | 'default' => NULL, |
| 1391 | 0 | ], |
| 1392 | 0 | 'progress_percent' => [ |
| 1393 | 0 | 'description' => 'The furthest position as a percent of the length', |
| 1394 | 0 | 'type' => 'int', |
| 1395 | 0 | 'not null' => FALSE, |
| 1396 | 0 | 'default' => NULL, |
| 1397 | 0 | ], |
| 1398 | 0 | 'time_to_play' => [ |
| 1399 | 0 | 'description' => 'Seconds from impression until the first play', |
| 1400 | 0 | 'type' => 'int', |
| 1401 | 0 | 'not null' => FALSE, |
| 1402 | 0 | 'default' => NULL, |
| 1403 | 0 | ], |
| 1404 | 0 | 'width' => [ |
| 1405 | 0 | 'description' => 'The video width in pixels', |
| 1406 | 0 | 'type' => 'int', |
| 1407 | 0 | 'not null' => FALSE, |
| 1408 | 0 | 'default' => NULL, |
| 1409 | 0 | ], |
| 1410 | 0 | 'height' => [ |
| 1411 | 0 | 'description' => 'The video height in pixels', |
| 1412 | 0 | 'type' => 'int', |
| 1413 | 0 | 'not null' => FALSE, |
| 1414 | 0 | 'default' => NULL, |
| 1415 | 0 | ], |
| 1416 | 0 | 'fullscreen' => [ |
| 1417 | 0 | 'description' => 'Whether the video was fullscreen', |
| 1418 | 0 | 'type' => 'int', |
| 1419 | 0 | 'size' => 'tiny', |
| 1420 | 0 | 'not null' => TRUE, |
| 1421 | 0 | 'default' => 0, |
| 1422 | 0 | ], |
| 1423 | 0 | 'play_count' => [ |
| 1424 | 0 | 'description' => 'How many times play started', |
| 1425 | 0 | 'type' => 'int', |
| 1426 | 0 | 'not null' => TRUE, |
| 1427 | 0 | 'default' => 0, |
| 1428 | 0 | ], |
| 1429 | 0 | 'finish_count' => [ |
| 1430 | 0 | 'description' => 'How many times playback finished', |
| 1431 | 0 | 'type' => 'int', |
| 1432 | 0 | 'not null' => TRUE, |
| 1433 | 0 | 'default' => 0, |
| 1434 | 0 | ], |
| 1435 | 0 | 'segments' => [ |
| 1436 | 0 | 'description' => 'Comma-separated positions that were consumed', |
| 1437 | 0 | 'type' => 'text', |
| 1438 | 0 | 'not null' => FALSE, |
| 1439 | 0 | ], |
| 1440 | 0 | 'created' => [ |
| 1441 | 0 | 'description' => 'When the media was first seen', |
| 1442 | 0 | 'type' => 'int', |
| 1443 | 0 | 'not null' => TRUE, |
| 1444 | 0 | ], |
| 1445 | 0 | 'changed' => [ |
| 1446 | 0 | 'description' => 'When the media row was last updated', |
| 1447 | 0 | 'type' => 'int', |
| 1448 | 0 | 'not null' => TRUE, |
| 1449 | 0 | ], |
| 1450 | 0 | ], |
| 1451 | 0 | 'primary key' => ['id'], |
| 1452 | 0 | 'unique keys' => [ |
| 1453 | 0 | 'visit_media' => ['visit_id', 'media_id'], |
| 1454 | 0 | ], |
| 1455 | 0 | 'indexes' => [ |
| 1456 | 0 | 'visit_id' => ['visit_id'], |
| 1457 | 0 | ], |
| 1458 | 0 | ]; |
| 1459 | } | |
| 1460 | ||
| 1461 | /** | |
| 1462 | * Adds the media log. | |
| 1463 | */ | |
| 1464 | function visitors_update_30010(): void { | |
| 1465 | 0 | $schema = \Drupal::database()->schema(); |
| 1466 | 0 | if ($schema->tableExists('visitors_media')) { |
| 1467 | 0 | return; |
| 1468 | } | |
| 1469 | 0 | $schema->createTable('visitors_media', visitors_media_schema()); |
| 1470 | } | |
| 1471 | ||
| 1472 | /** | |
| 1473 | * Adds time spent to each event. | |
| 1474 | */ | |
| 1475 | function visitors_update_30011(): void { | |
| 1476 | 0 | $schema = \Drupal::database()->schema(); |
| 1477 | 0 | if (!$schema->tableExists('visitors_event')) { |
| 1478 | 0 | return; |
| 1479 | } | |
| 1480 | 0 | if ($schema->fieldExists('visitors_event', 'time_spent')) { |
| 1481 | 0 | return; |
| 1482 | } | |
| 1483 | 0 | $schema->addField('visitors_event', 'time_spent', [ |
| 1484 | 0 | 'description' => 'Seconds on this page, or until the next event.', |
| 1485 | 0 | 'type' => 'int', |
| 1486 | 0 | 'unsigned' => TRUE, |
| 1487 | 0 | 'not null' => TRUE, |
| 1488 | 0 | 'default' => 0, |
| 1489 | 0 | ]); |
| 1490 | } | |
| 1491 | ||
| 1492 | /** | |
| 1493 | * Adds the Device Detector bot name to each visit. | |
| 1494 | */ | |
| 1495 | function visitors_update_30012(): void { | |
| 1496 | 0 | $schema = \Drupal::database()->schema(); |
| 1497 | 0 | if (!$schema->tableExists('visitors_visit')) { |
| 1498 | 0 | return; |
| 1499 | } | |
| 1500 | 0 | if ($schema->fieldExists('visitors_visit', 'bot_name')) { |
| 1501 | 0 | return; |
| 1502 | } | |
| 1503 | 0 | $schema->addField('visitors_visit', 'bot_name', [ |
| 1504 | 0 | 'description' => 'Device Detector bot name', |
| 1505 | 0 | 'type' => 'varchar', |
| 1506 | 0 | 'length' => 255, |
| 1507 | 0 | 'not null' => FALSE, |
| 1508 | 0 | 'default' => NULL, |
| 1509 | 0 | ]); |
| 1510 | } | |
| 1511 | ||
| 1512 | /** | |
| 1513 | * Adds the AI agent flag to each visit. | |
| 1514 | */ | |
| 1515 | function visitors_update_30013(): void { | |
| 1516 | 0 | $schema = \Drupal::database()->schema(); |
| 1517 | 0 | if (!$schema->tableExists('visitors_visit')) { |
| 1518 | 0 | return; |
| 1519 | } | |
| 1520 | 0 | if ($schema->fieldExists('visitors_visit', 'ai_agent')) { |
| 1521 | 0 | return; |
| 1522 | } | |
| 1523 | 0 | $schema->addField('visitors_visit', 'ai_agent', [ |
| 1524 | 0 | 'description' => 'The visit was opened by an AI agent browser.', |
| 1525 | 0 | 'type' => 'int', |
| 1526 | 0 | 'size' => 'tiny', |
| 1527 | 0 | 'unsigned' => TRUE, |
| 1528 | 0 | 'not null' => TRUE, |
| 1529 | 0 | 'default' => 0, |
| 1530 | 0 | ]); |
| 1531 | } | |
| 1532 | ||
| 1533 | /** | |
| 1534 | * Adds campaign dimension columns to each visit. | |
| 1535 | */ | |
| 1536 | function visitors_update_30014(): void { | |
| 1537 | 0 | $schema = \Drupal::database()->schema(); |
| 1538 | 0 | if (!$schema->tableExists('visitors_visit')) { |
| 1539 | 0 | return; |
| 1540 | } | |
| 1541 | $columns = [ | |
| 1542 | 'campaign_source' => 'The campaign source', | |
| 1543 | 'campaign_medium' => 'The campaign medium', | |
| 1544 | 'campaign_content' => 'The campaign content', | |
| 1545 | 'campaign_id' => 'The campaign id', | |
| 1546 | 'campaign_group' => 'The campaign group', | |
| 1547 | 'campaign_placement' => 'The campaign placement', | |
| 1548 | ]; | |
| 1549 | 0 | foreach ($columns as $name => $description) { |
| 1550 | 0 | if ($schema->fieldExists('visitors_visit', $name)) { |
| 1551 | continue; | |
| 1552 | } | |
| 1553 | 0 | $schema->addField('visitors_visit', $name, [ |
| 1554 | 0 | 'description' => $description, |
| 1555 | 0 | 'type' => 'varchar', |
| 1556 | 0 | 'length' => 255, |
| 1557 | 0 | 'not null' => FALSE, |
| 1558 | 0 | 'default' => NULL, |
| 1559 | 0 | ]); |
| 1560 | } | |
| 1561 | } |