Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
chore: Get meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
attiks committed Nov 2, 2023
1 parent a4c2076 commit f31e22b
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions html/sites/all/modules/hr/hr_core/hr_core.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,126 @@ function hr_core_drush_command() {
'aliases' => array(),
);

$items['hr-core-rwr-392'] = array(
'description' => "Extract meta data",
'drupal dependencies' => array(),
'aliases' => array(),
);

return $items;
}

/**
* Get the average file size of all files uploaded on HR.info.
*/
function drush_hr_core_rwr_392() {
$file = fopen('/var/www/rwr_links.csv', 'r');
$counter = 0;

// Skip header.
$row = fgetcsv($file);

while (($row = fgetcsv($file)) !== FALSE && $counter < 50) {
$counter++;
if ($row[8] == 'The linked content originates from a prior revision of a paragraph.') {
continue;
}

$url = $row[0];

// Check if it's a link to a node.
if (strpos($url, '/node/') !== FALSE) {
// Extract last part as nid.
$path = ltrim(parse_url($url, PHP_URL_PATH), '/');
$parts = explode('/', $path);
$nid = array_pop($parts);
}
// Lookup using alias.
else {
$url = parse_url($url, PHP_URL_PATH);
$parts = explode('/', $url);

// Remove language.
if ($parts[1] === 'en' || $parts[1] === 'es' || $parts[1] === 'fr' || $parts[1] === 'ru') {
unset($parts[1]);
$parts = array_values($parts);
}
$url = implode('/', $parts);

$nid = _hr_core_get_id_from_alias($url);

// If not found, search by title.
if (!$nid) {
// Extract last part as title.
$path = ltrim(parse_url($url, PHP_URL_PATH), '/');
$parts = explode('/', $path);
$title = array_pop($parts);
$title = urldecode($title);

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->propertyCondition('title', $title);
$result = $query->execute();

if ($result && isset($result['node'])) {
$nid = reset($result['node'])->nid;
}
}

// Replace dashes.
// If not found, search by title.
if (!$nid) {
// Extract last part as title.
$path = ltrim(parse_url($url, PHP_URL_PATH), '/');
$parts = explode('/', $path);
$title = array_pop($parts);
$title = urldecode($title);
$title = str_replace('-', ' ', $title);

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->propertyCondition('title', $title);
$result = $query->execute();

if ($result && isset($result['node'])) {
$nid = reset($result['node'])->nid;
}
}

}

drush_print_r([
$url,
$nid
]);
}
fclose($file);
}

/**
* Get Id from alias.
*/
function _hr_core_get_id_from_alias($url) {
$path = ltrim(parse_url($url, PHP_URL_PATH), '/');

// Check redirects and get final path.
if (function_exists('redirect_load_by_source')) {
if ($redirect = redirect_load_by_source($path)) {
$path = $redirect['redirect'];
}
}

$node_path = drupal_lookup_path('source', $path);

if (!$node_path) {
return FALSE;
}

$node = menu_get_object('node', 1, $node_path);

return $node->nid;
}

/**
* Get the average file size of all files uploaded on HR.info.
*/
Expand Down

0 comments on commit f31e22b

Please sign in to comment.