コード例 #1
0
 /**
  * check all links for a given table
  * alter links to reflect changes to the tablename
  *
  * @param string $table_name
  * @param string $table_name_new
  * @return mixed     true on success or PEAR_ERROR
  */
 function updateTableLinkRelations($table_name, $table_name_new)
 {
     if ($this->use_links) {
         if (!empty($this->links_trans)) {
             $aLinks = Openads_Links::readLinksDotIni($this->links_trans, $table_name);
             if (isset($aLinks[$table_name])) {
                 $aLinks[$table_name_new] = $aLinks[$table_name];
                 unset($aLinks[$table_name]);
             }
             foreach ($aLinks as $table => $aKeys) {
                 foreach ($aKeys as $field => $aTarget) {
                     if ($aTarget['table'] == $table_name) {
                         $aLinks[$table][$field]['table'] = $table_name_new;
                     }
                 }
             }
             return Openads_Links::writeLinksDotIni($this->links_trans, $aLinks);
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * A method to get all the required tables to create another table.
  *
  * @param string  $table  The table to check for.
  * @param array   $aLinks The links array, if already loaded.
  * @param array   $aSkip  The table(s) to skip (already checked).
  * @param integer $level  Recursion level.
  * @return array The required tables array.
  */
 function _getRequiredTables($table, $aLinks = null, $aSkip = null, $level = 0)
 {
     if (is_null($aLinks)) {
         require_once MAX_PATH . '/lib/OA/Dal/Links.php';
         $aLinks = Openads_Links::readLinksDotIni(MAX_PATH . '/lib/max/Dal/DataObjects/db_schema.links.ini');
     }
     $aTables = array();
     if (isset($aLinks[$table])) {
         foreach ($aLinks[$table] as $aLink) {
             $refTable = $aLink['table'];
             $aTables[$refTable] = $level;
             foreach (array_keys($aTables) as $refTable) {
                 if (!isset($aSkip[$refTable])) {
                     $aTables = $this->_getRequiredTables($refTable, $aLinks, $aTables, $level + 1) + $aTables;
                 }
             }
         }
     }
     if (!$level) {
         arsort($aTables);
         return array_keys($aTables);
     } else {
         return $aTables;
     }
 }