Index: branches/5.3.x/units/link_validation/link_validation_eh.php =================================================================== diff -u -N -r15672 -r15696 --- branches/5.3.x/units/link_validation/link_validation_eh.php (.../link_validation_eh.php) (revision 15672) +++ branches/5.3.x/units/link_validation/link_validation_eh.php (.../link_validation_eh.php) (revision 15696) @@ -1,6 +1,6 @@ getUnitConfig(); + // 1. delete previous validation results - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName'); + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName(); $ids = $this->Conn->GetCol($sql); - if ($ids) { - $temp_handler = $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + if ( $ids ) { + $temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); /* @var $temp_handler kTempTablesHandler */ $temp_handler->DeleteItems($event->Prefix, $event->Special, $ids); @@ -270,18 +272,21 @@ function _getRecycleBinCategories() { $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder'); - if (!is_numeric($recycle_bin)) { + + if ( !is_numeric($recycle_bin) ) { return Array (); } $recycle_categories = $this->Application->RecallVar('recycle_categories'); - if ($recycle_categories === false) { + + if ( $recycle_categories === false ) { + $categories_config = $this->Application->getUnitConfig('c'); $tree_indexes = $this->Application->getTreeIndex($recycle_bin); - $sql = 'SELECT ' . $this->Application->getUnitOption('c', 'IDField') . ' - FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' + $sql = 'SELECT ' . $categories_config->getIDField() . ' + FROM ' . $categories_config->getTableName() . ' WHERE TreeLeft BETWEEN ' . $tree_indexes['TreeLeft'] . ' AND ' . $tree_indexes['TreeRight']; - $recycle_categories = serialize( $this->Conn->GetCol($sql) ); + $recycle_categories = serialize($this->Conn->GetCol($sql)); // store recycle bin categories in session to prevent query below happening on each link validation step $this->Application->StoreVar('recycle_categories', $recycle_categories); @@ -301,40 +306,42 @@ { static $recycle_bin = null; - if (!isset($recycle_bin)) { + if ( !isset($recycle_bin) ) { $recycle_bin = $this->_getRecycleBinCategories(); } - if (!$recycle_bin) { + if ( !$recycle_bin ) { // Recycle Bin not used in system -> link is 100% not there return false; } $sql = 'SELECT CategoryId - FROM ' . $this->Application->getUnitOption('l-ci', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('l-ci')->getTableName() . ' WHERE ItemResourceId = ' . $resource_id . ' AND PrimaryCat = 1'; - return in_array( $this->Conn->GetOne($sql), $recycle_bin); + return in_array($this->Conn->GetOne($sql), $recycle_bin); } function _validateLink($link_id) { $curl_helper = $this->Application->recallObject('CurlHelper'); /* @var $curl_helper kCurlHelper */ + $link_config = $this->Application->getUnitConfig('l'); + $sql = 'SELECT Url, ResourceId - FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' - WHERE ' . $this->Application->getUnitOption('l', 'IDField') . ' = ' . $link_id; + FROM ' . $link_config->getTableName() . ' + WHERE ' . $link_config->getIDField() . ' = ' . $link_id; $link_data = $this->Conn->GetRow($sql); - if (!preg_match('/^(http|https):\/\/(.*)/U', $link_data['Url']) || $this->_inRecycleBin($link_data['ResourceId'])) { - return ; + if ( !preg_match('/^(http|https):\/\/(.*)/U', $link_data['Url']) || $this->_inRecycleBin($link_data['ResourceId']) ) { + return; } $curl_helper->timeout = LINK_VALIDATION_TIMEOUT; $result = $curl_helper->Send($link_data['Url']); - if ($result === false || $curl_helper->lastErrorMsg != '') { + if ( $result === false || $curl_helper->lastErrorMsg != '' ) { $curl_helper->lastErrorCode = 500; } @@ -352,6 +359,7 @@ 'ValidationCode' => $curl_helper->lastHTTPCode, 'ValidationStatus' => $curl_helper->lastHTTPCode < 400 ? LINK_VALIDATION_VALID : LINK_VALIDATION_INVALID, ); + $link_validation->SetDBFieldsFromHash($fields_hash); return $link_validation->isLoaded() ? $link_validation->Update() : $link_validation->Create(); @@ -394,10 +402,11 @@ */ function _getSelectedIds($event, $transform = false) { - $ids = Array(); + $ids = Array (); - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if ($items_info) { + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + + if ( $items_info ) { foreach ($items_info as $id => $field_values) { if ( getArrayValue($field_values, 'ForeignLinkId') ) { // we are not gathering ids by unit idfield here! @@ -406,9 +415,11 @@ } } - if ($transform && $ids) { - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + if ( $transform && $ids ) { + $config = $event->getUnitConfig(); + + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' WHERE LinkId IN (' . implode(',', $ids) . ')'; $ids = $this->Conn->GetCol($sql); } @@ -491,14 +502,14 @@ function OnPrepareLinkEditing($event) { // hook to OnAfterConfigRead instead of OnEdit, because fake ids should be available in CheckPermission - if ($this->Application->GetVar('l_event') != 'OnEdit') { - return ; + if ( $this->Application->GetVar('l_event') != 'OnEdit' ) { + return; } + $items_info = Array (); $ids = $this->_getSelectedIds($event); - $id_field = $this->Application->getUnitOption('l', 'IDField'); + $id_field = $this->Application->getUnitConfig('l')->getIDField(); - $items_info = Array (); foreach ($ids as $id) { $items_info[$id][$id_field] = 'on'; } @@ -516,19 +527,22 @@ function _prepareValidation($event) { // 2. get ids of all links and put them into validation queue - $id_field = $this->Application->getUnitOption('l', 'IDField'); - $sql = 'SELECT ' . $id_field . ' - FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' - WHERE LinkId NOT IN (SELECT LinkId FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ')'; + $links_config = $this->Application->getUnitConfig('l'); + + $sql = 'SELECT ' . $links_config->getIDField() . ' + FROM ' . $links_config->getTableName() . ' + WHERE LinkId NOT IN (SELECT LinkId FROM ' . $event->getUnitConfig()->getTableName() . ')'; $link_ids = $this->Conn->GetCol($sql); - if ($link_ids) { + if ( $link_ids ) { $validation_data = Array ( 'processed' => 0, 'total' => count($link_ids), 'items' => $link_ids, ); + $this->Application->StoreVar($event->Prefix . '_status', serialize($validation_data)); // 4K links will be 78KB serialized + return true; } @@ -563,9 +577,9 @@ { parent::OnAfterConfigRead($event); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $calculated_fields['']['LinkName'] = 'l.l' . $this->Application->GetVar('m_lang') . '_Name'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array ( + 'LinkName' => 'l.l' . $this->Application->GetVar('m_lang') . '_Name', + )); } } \ No newline at end of file