This commit is contained in:
calcu1on
2025-03-15 17:25:17 -04:00
parent 9dbfbeecef
commit d38d4aabc1
105 changed files with 2469 additions and 1484 deletions

View File

@@ -98,9 +98,9 @@ class FighterImporter {
else {
$fighters_by_div = self::getListOfCurrentFighters();
// Process each fighter into system.
foreach ($fighters_by_div as $division => $fighters) {
$this->processDivision($division, $fighters);
}
/* foreach ($fighters_by_div as $division => $fighters) { */
/* $this->processDivision($division, $fighters); */
/* } */
}
}
/**
@@ -109,9 +109,11 @@ class FighterImporter {
* @param mixed $div
* @param mixed $fighters
*/
private function processDivision($div, $fighters): void {
public static function processDivision($div, $fighters, &$context): void {
\Drupal::logger('ufc')->notice("Starting to update $div");
foreach ($fighters as $fighter_data) {
$fighter = new Fighter($this->httpClient);
$fighter = new Fighter(\Drupal::httpClient());
$fighter->first_name = $fighter_data['firstname'];
$fighter->last_name = $fighter_data['lastname'];
$fighter->image = $fighter_data['image'];
@@ -122,7 +124,7 @@ class FighterImporter {
// Check if node exists, by title.
$fighter->createMediaEntityFromImage();
$title = $fighter->first_name . " " . $fighter->last_name;
$node_lookup = reset($this->entityTypeManager->getStorage('node')->loadByProperties(['title' => $title]));
$node_lookup = reset(\Drupal::entityTypeManager()->getStorage('node')->loadByProperties(['title' => $title]));
if (!empty($node_lookup)) {
// Update instead of create.
@@ -134,6 +136,7 @@ class FighterImporter {
$fighter->createPlayerNode();
}
}
$context['results']['processed']++;
}
/**
@@ -157,7 +160,6 @@ class FighterImporter {
* @param string $base_url
*/
public function loopThroughFighterPages($base_url): void {
// Here you are Dan.
// Implement caching to store instead of needing fresh requests.
for ($i=0; $i<=100; $i++) {
$ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15';
@@ -165,7 +167,7 @@ class FighterImporter {
'referer' => true,
'verify' => false,
'headers' => [
'User-Agent' => 'DC SCRAPER/v1.0',
'User-Agent' => $ua,
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding' => 'gzip, deflate, br',
]