function createChildLinks($EN_US_mlid, $EngLinkTitle, $mlid_trans, $currentLanguage) { global $db, $error_log; $to_language = array($currentLanguage['sovee_code']); $msg = "Creating children for the {$currentLanguage} version of {$EngLinkTitle} -- {$EN_US_mlid} (which is mlid={$mlid_trans})\n"; fwrite($error_log, $msg); // Walk through the EN-US children of the given menu $translatedRow = $allrows = array(); // Find all non-hidden EN-US children of a given EN-US top-level (plid=0) menu $q1 = "SELECT * from menu_links WHERE menu_name='primary-links' and plid=\"" . $EN_US_mlid . "\" \n AND hidden=0 \n AND (options regexp 's:8:\"langcode\";s:5:\"en-us\"' OR options NOT regexp '\"langcode\"')\n ORDER BY weight"; // OR (options NOT regexp '\"langcode\"' AND link_path NOT regexp '^node/') $r1 = mysql_query($q1, $db); sqlErrors($q1); $msg = "q1 = {$q1}\n\n"; $msg .= "Children of {$EngLinkTitle} are:\n"; while ($myrow = mysql_fetch_assoc($r1)) { $allrows[] = $myrow; $msg .= " " . $myrow['link_title'] . "\n"; } fwrite($error_log, $msg); foreach ($allrows as $translatedRow) { $newPlid = $translatedRow['mlid']; $originalPlid = $translatedRow['plid']; $translatedRow['plid'] = $translatedRow['p1'] = $mlid_trans; $translatedLinkTitle = trim(translateString("en-us", $currentLanguage['sovee_code'], $translatedRow['link_title'])); $msg = "Translating " . $translatedRow['link_title'] . " to " . $currentLanguage['sovee_code'] . " gives {$translatedLinkTitle}\n\n"; fwrite($error_log, $msg); if (strlen($translatedLinkTitle) < 1) { // Use English if Sovee translation fails $msg = "> > > Unable to create " . $currentLanguage['sovee_code'] . " for \"" . $translatedRow['link_title'] . "\", using English\n\n"; fwrite($error_log, $msg); $translatedLinkTitle = $currentMenuAry['link_title']; } $translatedRow['link_title'] = $translatedLinkTitle; $translatedRow['options'] = "a:2:{s:10:\"attributes\";a:1:{s:5:\"title\";s:0:\"\";}s:8:\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";}"; $EN_US_mlid = $translatedRow['mlid']; $translatedRow['mlid'] = "NULL"; $linkPath = $translatedRow['link_path']; $nodeNumber = preg_replace("/node\\//", "", $linkPath); if (is_numeric($nodeNumber)) { $msg = "Going to translate node {$nodeNumber} into " . $currentLanguage['sovee_code'] . " . . .\n"; fwrite($error_log, $msg); // Does a translation already exist for this node? $existingTranslationAry = checkForTranslatedVersion($nodeNumber, $currentLanguage['drupal_code']); $msg = "Checking return from checkForTranslatedVersion\nexistingTranslationAry = \n"; $msg .= print_r($existingTranslationAry, TRUE); fwrite($error_log, $msg); if (isset($existingTranslationAry['nid'])) { $newNodeID = $existingTranslationAry['nid']; $translatedRow['link_title'] = $existingTranslationAry['title']; $q6 = "UPDATE node SET status=1, tnid=\"{$nodeNumber}\" WHERE nid=\"{$newNodeID}\" LIMIT 1"; $r7 = mysql_query($q6, $db); $msg = "An existing " . $currentLanguage['drupal_code'] . " translation for node {$nodeNumber}, which is node {$newNodeID}, \"" . $translatedRow['link_title'] . "\"\n"; $msg .= print_r($existingTranslationAry, TRUE); $msg .= $q6 . "\n"; fwrite($error_log, $msg); } else { // A translation does NOT exist. Create one $msg = "An existing " . $currentLanguage['drupal_code'] . " translation for node {$nodeNumber} does NOT exist.\n"; $msg .= print_r($existingTranslationAry, TRUE); fwrite($error_log, $msg); $testAry = translateOneNode($nodeNumber, $to_language, "Menu Generator"); $newNodeID = $testAry['nid']; } $q4 = "DELETE FROM menu_links WHERE link_path = \"node/" . $newNodeID . "\""; $r4 = mysql_query($q4, $db); sqlErrors($q4); $translatedRow['link_path'] = "node/" . $newNodeID; // Build the INSERT statement $q3 = "INSERT INTO menu_links SET "; foreach ($translatedRow as $key => $value) { if ($value != "NULL") { $q3 .= "{$key} = \"" . addslashes($value) . "\","; } else { $q3 .= "{$key} = NULL,"; } } $q3 = rtrim($q3, ','); $r3 = mysql_query($q3, $db); $err_msg = trim(mysql_error($db)); if (strlen($err_msg) > 0) { $msg = "MYSQL_ERROR: {$err_msg}\nQuery = {$q1}\n"; echo $msg; fwrite($error_log, $msg); } $msg1 = "q3 = {$q3}\n"; $r5 = mysql_query("SELECT LAST_INSERT_ID() as mlid", $db); // Get the mlid of the newly-inserted row while ($mtmp = mysql_fetch_assoc($r5)) { $mlid_last = $mtmp['mlid']; } $q4 = "UPDATE menu_links SET p2 = mlid WHERE mlid=\"" . $mlid_last . "\" LIMIT 1"; $msg1 .= "Q4 = {$q4}\n\n"; $r4 = mysql_query($q4, $db); sqlErrors($q4); fwrite($error_log, $msg1); // End of if (is_numeric($nodeNumber)) //yes// } else { // Handle link_path without node identifier // ADD NEW CODE FOR LINK_PATH $msg = "Looking for link_paths without node identifiers in " . $currentLanguage['drupal_code'] . "\n\n"; fwrite($error_log, $msg); $q5a = "SELECT mlid, link_title from menu_links where link_path = \"{$linkPath}\"\n AND menu_name = 'primary-links'\n AND options regexp '\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";'\n ORDER BY hidden ASC\n\t\t\tLIMIT 1"; // We need only one value, take the first visible one, if multiple are present $r5a = mysql_query($q5a, $db); sqlErrors($q5a); if (mysql_num_rows($r5a) > 0) { while ($m5a = mysql_fetch_assoc($r5a)) { $thisMlid = $m5a['mlid']; $thisLinkTitle = $m5a['link_title']; $msg = "Found {$thisLinkTitle} at mlid={$thisMlid}\n"; fwrite($error_log, $msg); } $q6a = "UPDATE menu_links SET plid='" . $mlid_trans . "', p1='" . $mlid_trans . "', hidden='0', \n\t\t\t\tlink_title = '" . $translatedLinkTitle . "'\n WHERE mlid='" . $thisMlid . "'"; $msg = "q6a = {$q6a}\n"; fwrite($error_log, $msg); $r6a = mysql_query($q6a, $db); sqlErrors($q6a); } else { //INSERT NEW ROW, GRAB NEW MLID, POPULATE p1 $q6a = "INSERT INTO menu_links SET\n\t\t\tmenu_name = 'primary-links',\n\t\t\tmlid = NULL,\n\t\t\tplid = '" . $mlid_trans . "',\n\t\t\tlink_path = '" . $linkPath . "',\n\t\t\trouter_path = '" . $translatedRow['router_path'] . "',\n\t\t link_title = '" . $translatedLinkTitle . "',\n\t\t\toptions = 'a:2:{s:10:\"attributes\";a:1:{s:5:\"title\";s:0:\"\";}s:8:\"langcode\";s:" . strlen($currentLanguage['drupal_code']) . ":\"" . $currentLanguage['drupal_code'] . "\";}',\n\t\t\tmodule = '" . $translatedRow['module'] . "', \n\t\t\thidden = '0',\n\t\t\texternal = '" . $translatedRow['external'] . "',\n\t\t\thas_children = '" . $translatedRow['has_children'] . "',\n expanded = '" . $translatedRow['expanded'] . "',\n weight = '" . $translatedRow['weight'] . "',\n depth = '" . $translatedRow['depth'] . "',\n customized = '" . $translatedRow['customized'] . "',\n\t\t\tp1 = '" . $mlid_trans . "',\n\t\t\tupdated = '0'"; $msg = "q6a = {$q6a}\n"; fwrite($error_log, $msg); $r6a = mysql_query($q6a, $db); sqlErrors($q6a); $r7 = mysql_query("SELECT LAST_INSERT_ID() as mlid", $db); // Get the mlid of the newly-inserted row while ($mtmp = mysql_fetch_assoc($r7)) { $mlid_last = $mtmp['mlid']; } $q6b = "UPDATE menu_links SET p1 = mlid WHERE mlid=\"" . $mlid_last . "\" LIMIT 1"; $r6b = mysql_query($q6b, $db); $msg = "q6b = {$q6b}\n"; sqlErrors($q6b); } } // End of if (is_numeric($nodeNumber)) } // End of foreach($allrows as $translatedRow) }
#!/usr/bin/php <?php // SQL: qs3 = SELECT nid,title from node where tnid="49302" AND status=1 AND (language="de" OR language="") include "includes/db_config.php"; $db = mysql_connect($dbserver, $dbuser, $dbpass); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $db); $error_log = fopen("/home/sonosite/cjacks/translate/logs/" . "test_error.log", "w"); $foo = checkForTranslatedVersion(49302, "de"); print_r($foo); if (!isset($noggin)) { echo "noggis is NOT set\n\n"; } else { echo "noggin is set"; } if (isset($foo['nid'])) { echo "IS SET\n"; } # ========================================================================== # Does a translation exist for the given node? # Args: $thisTnid = Node number of the node to check # $langCode = Drupal code of the language # # Return: Array(nid, title) function checkForTranslatedVersion($thisTnid, $langCode) { global $error_log, $db; $TranslatedNodeAry = array(); if ($thisTnid > 0) {