Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 34... Línea 34...
34
     * Init method, every subclass will have its own
34
     * Init method, every subclass will have its own
35
     */
35
     */
36
    function init() {
36
    function init() {
37
        parent::init();
37
        parent::init();
Línea -... Línea 38...
-
 
38
 
-
 
39
        global $DB;
-
 
40
        if ($DB->get_dbfamily() !== 'mysql') {
-
 
41
            throw new moodle_exception('DB family not supported');
-
 
42
        }
38
 
43
 
Línea 39... Línea 44...
39
        // Set own custom attributes
44
        // Set own custom attributes
40
 
45
 
41
        // Get needed strings
46
        // Get needed strings
Línea 53... Línea 58...
53
     * errormsg and output as necessary
58
     * errormsg and output as necessary
54
     */
59
     */
55
    function invoke() {
60
    function invoke() {
56
        parent::invoke();
61
        parent::invoke();
Línea 57... Línea -...
57
 
-
 
58
        $result = true;
-
 
59
 
62
 
60
        // Set own core attributes
63
        // Set own core attributes
Línea 61... Línea 64...
61
        $this->does_generate = ACTION_GENERATE_HTML;
64
        $this->does_generate = ACTION_GENERATE_HTML;
62
 
65
 
Línea 123... Línea 126...
123
 
126
 
124
 
127
 
125
        // If table, retrofit information and, if everything works,
128
        // If table, retrofit information and, if everything works,
126
        // go to the table edit action
129
        // go to the table edit action
127
        } else {
130
        } else {
128
            // Get some params (table is mandatory here)
131
            // Get some params (table is mandatory here).
-
 
132
            $tableparam = required_param('table', PARAM_ALPHAEXT);
-
 
133
            $afterparam = required_param('after', PARAM_ALPHAEXT);
-
 
134
 
-
 
135
            if (empty($tableparam) || empty($afterparam)) {
Línea 129... Línea 136...
129
            $tableparam = required_param('table', PARAM_CLEAN);
136
                throw new moodle_exception('Invalid param value detected.');
130
            $afterparam = required_param('after', PARAM_CLEAN);
137
            }
131
 
138
 
132
            // Create one new xmldb_table
139
            // Create one new xmldb_table.
133
            $table = new xmldb_table(strtolower(trim($tableparam)));
140
            $table = new xmldb_table(strtolower(trim($tableparam)));
134
            $table->setComment($table->getName() . ' table retrofitted from MySQL');
141
            $table->setComment($table->getName() . ' table retrofitted from MySQL');
Línea 145... Línea 152...
145
                }
152
                }
146
            }
153
            }
147
            // Get PK, UK and indexes info from ADODb
154
            // Get PK, UK and indexes info from ADODb
148
            $dbindexes = $DB->get_indexes($tableparam);
155
            $dbindexes = $DB->get_indexes($tableparam);
149
            if ($dbindexes) {
156
            if ($dbindexes) {
150
                $lastkey = NULL; //To temp store the last key processed
-
 
151
                foreach ($dbindexes as $indexname => $dbindex) {
157
                foreach ($dbindexes as $indexname => $dbindex) {
152
                    // Add the indexname to the array
158
                    // Add the indexname to the array
153
                    $dbindex['name'] = $indexname;
159
                    $dbindex['name'] = $indexname;
154
                    // We are handling one xmldb_key (primaries + uniques)
160
                    // We are handling one xmldb_key (primaries + uniques)
155
                    if ($dbindex['unique']) {
161
                    if ($dbindex['unique']) {
156
                        $key = new xmldb_key(strtolower($dbindex['name']));
162
                        $key = new xmldb_key(strtolower($dbindex['name']));
157
                        // Set key with info retrofitted
163
                        // Set key with info retrofitted
158
                        $key->setFromADOKey($dbindex);
164
                        $key->setFromADOKey($dbindex);
159
                        // Set default comment to PKs
-
 
160
                        if ($key->getType() == XMLDB_KEY_PRIMARY) {
-
 
161
                        }
-
 
162
                        // Add key to the table
165
                        // Add key to the table
163
                        $table->addKey($key);
166
                        $table->addKey($key);
Línea 164... Línea 167...
164
 
167
 
165
                    // We are handling one xmldb_index (non-uniques)
168
                    // We are handling one xmldb_index (non-uniques)
Línea 170... Línea 173...
170
                        // Add index to the table
173
                        // Add index to the table
171
                        $table->addIndex($index);
174
                        $table->addIndex($index);
172
                    }
175
                    }
173
                }
176
                }
174
            }
177
            }
175
            // Finally, add the whole retroffited table to the structure
178
            // Finally, add the whole retrofitted table to the structure in the place specified.
176
            // in the place specified
-
 
177
            $structure->addTable($table, $afterparam);
179
            $structure->addTable($table, $afterparam);
178
        }
180
        }
Línea 179... Línea 181...
179
 
181
 
180
        // Launch postaction if exists (leave this here!)
182
        // Launch postaction if exists (leave this here!)
181
        if ($this->getPostAction() && $result) {
183
        if ($this->getPostAction()) {
182
            return $this->launch($this->getPostAction());
184
            return $this->launch($this->getPostAction());
Línea 183... Línea 185...
183
        }
185
        }
184
 
186
 
185
        // Return ok if arrived here
187
        // Return ok if arrived here
186
        return $result;
188
        return true;