How to use getName method of are class

Best Mockery code snippet using are.getName

database_manager.php

Source:database_manager.php Github

copy

Full Screen

...98 if (!is_string($table) and !($table instanceof xmldb_table)) {99 throw new ddl_exception('ddlunknownerror', NULL, 'incorrect table parameter!');100 } else {101 if ($table instanceof xmldb_table) {102 $tablename = $table->getName();103 } else {104 $tablename = $table;105 }106 }107 // Do not test if table exists because it is slow108 if (!$sqlarr = $this->generator->getResetSequenceSQL($table)) {109 throw new ddl_exception('ddlunknownerror', null, 'table reset sequence sql not generated');110 }111 $this->execute_sql_arr($sqlarr, array($tablename));112 }113 /**114 * Given one xmldb_field, check if it exists in DB (true/false).115 *116 * @param string|xmldb_table $table The table to be searched (string name or xmldb_table instance).117 * @param string|xmldb_field $field The field to be searched for (string name or xmldb_field instance).118 * @return boolean true is exists false otherwise.119 * @throws ddl_table_missing_exception120 */121 public function field_exists($table, $field) {122 // Calculate the name of the table123 if (is_string($table)) {124 $tablename = $table;125 } else {126 $tablename = $table->getName();127 }128 // Check the table exists129 if (!$this->table_exists($table)) {130 throw new ddl_table_missing_exception($tablename);131 }132 if (is_string($field)) {133 $fieldname = $field;134 } else {135 // Calculate the name of the table136 $fieldname = $field->getName();137 }138 // Get list of fields in table139 $columns = $this->mdb->get_columns($tablename);140 $exists = array_key_exists($fieldname, $columns);141 return $exists;142 }143 /**144 * Given one xmldb_index, the function returns the name of the index in DB145 * of false if it doesn't exist146 *147 * @param xmldb_table $xmldb_table table to be searched148 * @param xmldb_index $xmldb_index the index to be searched149 * @param bool $returnall true means return array of all indexes, false means first index only as string150 * @return array|string|bool Index name, array of index names or false if no indexes are found.151 * @throws ddl_table_missing_exception Thrown when table is not found.152 */153 public function find_index_name(xmldb_table $xmldb_table, xmldb_index $xmldb_index, $returnall = false) {154 // Calculate the name of the table155 $tablename = $xmldb_table->getName();156 // Check the table exists157 if (!$this->table_exists($xmldb_table)) {158 throw new ddl_table_missing_exception($tablename);159 }160 // Extract index columns161 $indcolumns = $xmldb_index->getFields();162 // Get list of indexes in table163 $indexes = $this->mdb->get_indexes($tablename);164 $return = array();165 // Iterate over them looking for columns coincidence166 foreach ($indexes as $indexname => $index) {167 $columns = $index['columns'];168 // Check if index matches queried index169 $diferences = array_merge(array_diff($columns, $indcolumns), array_diff($indcolumns, $columns));170 // If no differences, we have find the index171 if (empty($diferences)) {172 if ($returnall) {173 $return[] = $indexname;174 } else {175 return $indexname;176 }177 }178 }179 if ($return and $returnall) {180 return $return;181 }182 // Arriving here, index not found183 return false;184 }185 /**186 * Given one xmldb_index, check if it exists in DB (true/false).187 *188 * @param xmldb_table $xmldb_table The table to be searched.189 * @param xmldb_index $xmldb_index The index to be searched for.190 * @return boolean true id index exists, false otherwise.191 */192 public function index_exists(xmldb_table $xmldb_table, xmldb_index $xmldb_index) {193 if (!$this->table_exists($xmldb_table)) {194 return false;195 }196 return ($this->find_index_name($xmldb_table, $xmldb_index) !== false);197 }198 /**199 * This function IS NOT IMPLEMENTED. ONCE WE'LL BE USING RELATIONAL200 * INTEGRITY IT WILL BECOME MORE USEFUL. FOR NOW, JUST CALCULATE "OFFICIAL"201 * KEY NAMES WITHOUT ACCESSING TO DB AT ALL.202 * Given one xmldb_key, the function returns the name of the key in DB (if exists)203 * of false if it doesn't exist204 *205 * @param xmldb_table $xmldb_table The table to be searched.206 * @param xmldb_key $xmldb_key The key to be searched.207 * @return string key name if found208 */209 public function find_key_name(xmldb_table $xmldb_table, xmldb_key $xmldb_key) {210 $keycolumns = $xmldb_key->getFields();211 // Get list of keys in table212 // first primaries (we aren't going to use this now, because the MetaPrimaryKeys is awful)213 //TODO: To implement when we advance in relational integrity214 // then uniques (note that Moodle, for now, shouldn't have any UNIQUE KEY for now, but unique indexes)215 //TODO: To implement when we advance in relational integrity (note that AdoDB hasn't any MetaXXX for this.216 // then foreign (note that Moodle, for now, shouldn't have any FOREIGN KEY for now, but indexes)217 //TODO: To implement when we advance in relational integrity (note that AdoDB has one MetaForeignKeys()218 //but it's far from perfect.219 // TODO: To create the proper functions inside each generator to retrieve all the needed KEY info (name220 // columns, reftable and refcolumns221 // So all we do is to return the official name of the requested key without any confirmation!)222 // One exception, hardcoded primary constraint names223 if ($this->generator->primary_key_name && $xmldb_key->getType() == XMLDB_KEY_PRIMARY) {224 return $this->generator->primary_key_name;225 } else {226 // Calculate the name suffix227 switch ($xmldb_key->getType()) {228 case XMLDB_KEY_PRIMARY:229 $suffix = 'pk';230 break;231 case XMLDB_KEY_UNIQUE:232 $suffix = 'uk';233 break;234 case XMLDB_KEY_FOREIGN_UNIQUE:235 case XMLDB_KEY_FOREIGN:236 $suffix = 'fk';237 break;238 }239 // And simply, return the official name240 return $this->generator->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), $suffix);241 }242 }243 /**244 * This function will delete all tables found in XMLDB file from db245 *246 * @param string $file Full path to the XML file to be used.247 * @return void248 */249 public function delete_tables_from_xmldb_file($file) {250 $xmldb_file = new xmldb_file($file);251 if (!$xmldb_file->fileExists()) {252 throw new ddl_exception('ddlxmlfileerror', null, 'File does not exist');253 }254 $loaded = $xmldb_file->loadXMLStructure();255 $structure = $xmldb_file->getStructure();256 if (!$loaded || !$xmldb_file->isLoaded()) {257 // Show info about the error if we can find it258 if ($structure) {259 if ($errors = $structure->getAllErrors()) {260 throw new ddl_exception('ddlxmlfileerror', null, 'Errors found in XMLDB file: '. implode (', ', $errors));261 }262 }263 throw new ddl_exception('ddlxmlfileerror', null, 'not loaded??');264 }265 if ($xmldb_tables = $structure->getTables()) {266 // Delete in opposite order, this should help with foreign keys in the future.267 $xmldb_tables = array_reverse($xmldb_tables);268 foreach($xmldb_tables as $table) {269 if ($this->table_exists($table)) {270 $this->drop_table($table);271 }272 }273 }274 }275 /**276 * This function will drop the table passed as argument277 * and all the associated objects (keys, indexes, constraints, sequences, triggers)278 * will be dropped too.279 *280 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).281 * @return void282 */283 public function drop_table(xmldb_table $xmldb_table) {284 // Check table exists285 if (!$this->table_exists($xmldb_table)) {286 throw new ddl_table_missing_exception($xmldb_table->getName());287 }288 if (!$sqlarr = $this->generator->getDropTableSQL($xmldb_table)) {289 throw new ddl_exception('ddlunknownerror', null, 'table drop sql not generated');290 }291 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));292 }293 /**294 * Load an install.xml file, checking that it exists, and that the structure is OK.295 * @param string $file the full path to the XMLDB file.296 * @return xmldb_file the loaded file.297 */298 private function load_xmldb_file($file) {299 $xmldb_file = new xmldb_file($file);300 if (!$xmldb_file->fileExists()) {301 throw new ddl_exception('ddlxmlfileerror', null, 'File does not exist');302 }303 $loaded = $xmldb_file->loadXMLStructure();304 if (!$loaded || !$xmldb_file->isLoaded()) {305 // Show info about the error if we can find it306 if ($structure = $xmldb_file->getStructure()) {307 if ($errors = $structure->getAllErrors()) {308 throw new ddl_exception('ddlxmlfileerror', null, 'Errors found in XMLDB file: '. implode (', ', $errors));309 }310 }311 throw new ddl_exception('ddlxmlfileerror', null, 'not loaded??');312 }313 return $xmldb_file;314 }315 /**316 * This function will load one entire XMLDB file and call install_from_xmldb_structure.317 *318 * @param string $file full path to the XML file to be used319 * @return void320 */321 public function install_from_xmldb_file($file) {322 $xmldb_file = $this->load_xmldb_file($file);323 $xmldb_structure = $xmldb_file->getStructure();324 $this->install_from_xmldb_structure($xmldb_structure);325 }326 /**327 * This function will load one entire XMLDB file and call install_from_xmldb_structure.328 *329 * @param string $file full path to the XML file to be used330 * @param string $tablename the name of the table.331 * @param bool $cachestructures boolean to decide if loaded xmldb structures can be safely cached332 * useful for testunits loading the enormous main xml file hundred of times (100x)333 */334 public function install_one_table_from_xmldb_file($file, $tablename, $cachestructures = false) {335 static $xmldbstructurecache = array(); // To store cached structures336 if (!empty($xmldbstructurecache) && array_key_exists($file, $xmldbstructurecache)) {337 $xmldb_structure = $xmldbstructurecache[$file];338 } else {339 $xmldb_file = $this->load_xmldb_file($file);340 $xmldb_structure = $xmldb_file->getStructure();341 if ($cachestructures) {342 $xmldbstructurecache[$file] = $xmldb_structure;343 }344 }345 $targettable = $xmldb_structure->getTable($tablename);346 if (is_null($targettable)) {347 throw new ddl_exception('ddlunknowntable', null, 'The table ' . $tablename . ' is not defined in file ' . $file);348 }349 $targettable->setNext(NULL);350 $targettable->setPrevious(NULL);351 $tempstructure = new xmldb_structure('temp');352 $tempstructure->addTable($targettable);353 $this->install_from_xmldb_structure($tempstructure);354 }355 /**356 * This function will generate all the needed SQL statements, specific for each357 * RDBMS type and, finally, it will execute all those statements against the DB.358 *359 * @param stdClass $xmldb_structure xmldb_structure object.360 * @return void361 */362 public function install_from_xmldb_structure($xmldb_structure) {363 if (!$sqlarr = $this->generator->getCreateStructureSQL($xmldb_structure)) {364 return; // nothing to do365 }366 $tablenames = array();367 foreach ($xmldb_structure as $xmldb_table) {368 if ($xmldb_table instanceof xmldb_table) {369 $tablenames[] = $xmldb_table->getName();370 }371 }372 $this->execute_sql_arr($sqlarr, $tablenames);373 }374 /**375 * This function will create the table passed as argument with all its376 * fields/keys/indexes/sequences, everything based in the XMLDB object377 *378 * @param xmldb_table $xmldb_table Table object (full specs are required).379 * @return void380 */381 public function create_table(xmldb_table $xmldb_table) {382 // Check table doesn't exist383 if ($this->table_exists($xmldb_table)) {384 throw new ddl_exception('ddltablealreadyexists', $xmldb_table->getName());385 }386 if (!$sqlarr = $this->generator->getCreateTableSQL($xmldb_table)) {387 throw new ddl_exception('ddlunknownerror', null, 'table create sql not generated');388 }389 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));390 }391 /**392 * This function will create the temporary table passed as argument with all its393 * fields/keys/indexes/sequences, everything based in the XMLDB object394 *395 * If table already exists ddl_exception will be thrown, please make sure396 * the table name does not collide with existing normal table!397 *398 * @param xmldb_table $xmldb_table Table object (full specs are required).399 * @return void400 */401 public function create_temp_table(xmldb_table $xmldb_table) {402 // Check table doesn't exist403 if ($this->table_exists($xmldb_table)) {404 throw new ddl_exception('ddltablealreadyexists', $xmldb_table->getName());405 }406 if (!$sqlarr = $this->generator->getCreateTempTableSQL($xmldb_table)) {407 throw new ddl_exception('ddlunknownerror', null, 'temp table create sql not generated');408 }409 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));410 }411 /**412 * This function will drop the temporary table passed as argument with all its413 * fields/keys/indexes/sequences, everything based in the XMLDB object414 *415 * It is recommended to drop temp table when not used anymore.416 *417 * @deprecated since 2.3, use drop_table() for all table types418 * @param xmldb_table $xmldb_table Table object.419 * @return void420 */421 public function drop_temp_table(xmldb_table $xmldb_table) {422 debugging('database_manager::drop_temp_table() is deprecated, use database_manager::drop_table() instead');423 $this->drop_table($xmldb_table);424 }425 /**426 * This function will rename the table passed as argument427 * Before renaming the index, the function will check it exists428 *429 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).430 * @param string $newname New name of the index.431 * @return void432 */433 public function rename_table(xmldb_table $xmldb_table, $newname) {434 // Check newname isn't empty435 if (!$newname) {436 throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');437 }438 $check = new xmldb_table($newname);439 // Check table already renamed440 if (!$this->table_exists($xmldb_table)) {441 if ($this->table_exists($check)) {442 throw new ddl_exception('ddlunknownerror', null, 'table probably already renamed');443 } else {444 throw new ddl_table_missing_exception($xmldb_table->getName());445 }446 }447 // Check new table doesn't exist448 if ($this->table_exists($check)) {449 throw new ddl_exception('ddltablealreadyexists', $check->getName(), 'can not rename table');450 }451 if (!$sqlarr = $this->generator->getRenameTableSQL($xmldb_table, $newname)) {452 throw new ddl_exception('ddlunknownerror', null, 'table rename sql not generated');453 }454 $this->execute_sql_arr($sqlarr);455 }456 /**457 * This function will add the field to the table passed as arguments458 *459 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).460 * @param xmldb_field $xmldb_field Index object (full specs are required).461 * @return void462 */463 public function add_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {464 // Check the field doesn't exist465 if ($this->field_exists($xmldb_table, $xmldb_field)) {466 throw new ddl_exception('ddlfieldalreadyexists', $xmldb_field->getName());467 }468 // If NOT NULL and no default given (we ask the generator about the469 // *real* default that will be used) check the table is empty470 if ($xmldb_field->getNotNull() && $this->generator->getDefaultValue($xmldb_field) === NULL && $this->mdb->count_records($xmldb_table->getName())) {471 throw new ddl_exception('ddlunknownerror', null, 'Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .472 ' cannot be added. Not null fields added to non empty tables require default value. Create skipped');473 }474 if (!$sqlarr = $this->generator->getAddFieldSQL($xmldb_table, $xmldb_field)) {475 throw new ddl_exception('ddlunknownerror', null, 'addfield sql not generated');476 }477 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));478 }479 /**480 * This function will drop the field from the table passed as arguments481 *482 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).483 * @param xmldb_field $xmldb_field Index object (full specs are required).484 * @return void485 */486 public function drop_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {487 if (!$this->table_exists($xmldb_table)) {488 throw new ddl_table_missing_exception($xmldb_table->getName());489 }490 // Check the field exists491 if (!$this->field_exists($xmldb_table, $xmldb_field)) {492 throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());493 }494 // Check for dependencies in the DB before performing any action495 $this->check_field_dependencies($xmldb_table, $xmldb_field);496 if (!$sqlarr = $this->generator->getDropFieldSQL($xmldb_table, $xmldb_field)) {497 throw new ddl_exception('ddlunknownerror', null, 'drop_field sql not generated');498 }499 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));500 }501 /**502 * This function will change the type of the field in the table passed as arguments503 *504 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).505 * @param xmldb_field $xmldb_field Index object (full specs are required).506 * @return void507 */508 public function change_field_type(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {509 if (!$this->table_exists($xmldb_table)) {510 throw new ddl_table_missing_exception($xmldb_table->getName());511 }512 // Check the field exists513 if (!$this->field_exists($xmldb_table, $xmldb_field)) {514 throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());515 }516 // Check for dependencies in the DB before performing any action517 $this->check_field_dependencies($xmldb_table, $xmldb_field);518 if (!$sqlarr = $this->generator->getAlterFieldSQL($xmldb_table, $xmldb_field)) {519 return; // probably nothing to do520 }521 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));522 }523 /**524 * This function will change the precision of the field in the table passed as arguments525 *526 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).527 * @param xmldb_field $xmldb_field Index object (full specs are required).528 * @return void529 */530 public function change_field_precision(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {531 // Just a wrapper over change_field_type. Does exactly the same processing532 $this->change_field_type($xmldb_table, $xmldb_field);533 }534 /**535 * This function will change the unsigned/signed of the field in the table passed as arguments536 *537 * @deprecated since 2.3, only singed numbers are allowed now, migration is automatic538 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).539 * @param xmldb_field $xmldb_field Field object (full specs are required).540 * @return void541 */542 public function change_field_unsigned(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {543 debugging('All unsigned numbers are converted to signed automatically during Moodle upgrade.');544 $this->change_field_type($xmldb_table, $xmldb_field);545 }546 /**547 * This function will change the nullability of the field in the table passed as arguments548 *549 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).550 * @param xmldb_field $xmldb_field Index object (full specs are required).551 * @return void552 */553 public function change_field_notnull(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {554 // Just a wrapper over change_field_type. Does exactly the same processing555 $this->change_field_type($xmldb_table, $xmldb_field);556 }557 /**558 * This function will change the default of the field in the table passed as arguments559 * One null value in the default field means delete the default560 *561 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).562 * @param xmldb_field $xmldb_field Index object (full specs are required).563 * @return void564 */565 public function change_field_default(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {566 if (!$this->table_exists($xmldb_table)) {567 throw new ddl_table_missing_exception($xmldb_table->getName());568 }569 // Check the field exists570 if (!$this->field_exists($xmldb_table, $xmldb_field)) {571 throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());572 }573 // Check for dependencies in the DB before performing any action574 $this->check_field_dependencies($xmldb_table, $xmldb_field);575 if (!$sqlarr = $this->generator->getModifyDefaultSQL($xmldb_table, $xmldb_field)) {576 return; //Empty array = nothing to do = no error577 }578 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));579 }580 /**581 * This function will rename the field in the table passed as arguments582 * Before renaming the field, the function will check it exists583 *584 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).585 * @param xmldb_field $xmldb_field Index object (full specs are required).586 * @param string $newname New name of the field.587 * @return void588 */589 public function rename_field(xmldb_table $xmldb_table, xmldb_field $xmldb_field, $newname) {590 if (empty($newname)) {591 throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');592 }593 if (!$this->table_exists($xmldb_table)) {594 throw new ddl_table_missing_exception($xmldb_table->getName());595 }596 // Check the field exists597 if (!$this->field_exists($xmldb_table, $xmldb_field)) {598 throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());599 }600 // Check we have included full field specs601 if (!$xmldb_field->getType()) {602 throw new ddl_exception('ddlunknownerror', null,603 'Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .604 ' must contain full specs. Rename skipped');605 }606 // Check field isn't id. Renaming over that field is not allowed607 if ($xmldb_field->getName() == 'id') {608 throw new ddl_exception('ddlunknownerror', null,609 'Field ' . $xmldb_table->getName() . '->' . $xmldb_field->getName() .610 ' cannot be renamed. Rename skipped');611 }612 if (!$sqlarr = $this->generator->getRenameFieldSQL($xmldb_table, $xmldb_field, $newname)) {613 return; //Empty array = nothing to do = no error614 }615 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));616 }617 /**618 * This function will check, for the given table and field, if there there is any dependency619 * preventing the field to be modified. It's used by all the public methods that perform any620 * DDL change on fields, throwing one ddl_dependency_exception if dependencies are found.621 *622 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).623 * @param xmldb_field $xmldb_field Index object (full specs are required).624 * @return void625 * @throws ddl_dependency_exception|ddl_field_missing_exception|ddl_table_missing_exception if dependency not met.626 */627 private function check_field_dependencies(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {628 // Check the table exists629 if (!$this->table_exists($xmldb_table)) {630 throw new ddl_table_missing_exception($xmldb_table->getName());631 }632 // Check the field exists633 if (!$this->field_exists($xmldb_table, $xmldb_field)) {634 throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());635 }636 // Check the field isn't in use by any index in the table637 if ($indexes = $this->mdb->get_indexes($xmldb_table->getName(), false)) {638 foreach ($indexes as $indexname => $index) {639 $columns = $index['columns'];640 if (in_array($xmldb_field->getName(), $columns)) {641 throw new ddl_dependency_exception('column', $xmldb_table->getName() . '->' . $xmldb_field->getName(),642 'index', $indexname . ' (' . implode(', ', $columns) . ')');643 }644 }645 }646 }647 /**648 * This function will create the key in the table passed as arguments649 *650 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).651 * @param xmldb_key $xmldb_key Index object (full specs are required).652 * @return void653 */654 public function add_key(xmldb_table $xmldb_table, xmldb_key $xmldb_key) {655 if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) { // Prevent PRIMARY to be added (only in create table, being serious :-P)656 throw new ddl_exception('ddlunknownerror', null, 'Primary Keys can be added at table create time only');657 }658 if (!$sqlarr = $this->generator->getAddKeySQL($xmldb_table, $xmldb_key)) {659 return; //Empty array = nothing to do = no error660 }661 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));662 }663 /**664 * This function will drop the key in the table passed as arguments665 *666 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).667 * @param xmldb_key $xmldb_key Key object (full specs are required).668 * @return void669 */670 public function drop_key(xmldb_table $xmldb_table, xmldb_key $xmldb_key) {671 if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) { // Prevent PRIMARY to be dropped (only in drop table, being serious :-P)672 throw new ddl_exception('ddlunknownerror', null, 'Primary Keys can be deleted at table drop time only');673 }674 if (!$sqlarr = $this->generator->getDropKeySQL($xmldb_table, $xmldb_key)) {675 return; //Empty array = nothing to do = no error676 }677 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));678 }679 /**680 * This function will rename the key in the table passed as arguments681 * Experimental. Shouldn't be used at all in normal installation/upgrade!682 *683 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).684 * @param xmldb_key $xmldb_key key object (full specs are required).685 * @param string $newname New name of the key.686 * @return void687 */688 public function rename_key(xmldb_table $xmldb_table, xmldb_key $xmldb_key, $newname) {689 debugging('rename_key() is one experimental feature. You must not use it in production!', DEBUG_DEVELOPER);690 // Check newname isn't empty691 if (!$newname) {692 throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');693 }694 if (!$sqlarr = $this->generator->getRenameKeySQL($xmldb_table, $xmldb_key, $newname)) {695 throw new ddl_exception('ddlunknownerror', null, 'Some DBs do not support key renaming (MySQL, PostgreSQL, MsSQL). Rename skipped');696 }697 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));698 }699 /**700 * This function will create the index in the table passed as arguments701 * Before creating the index, the function will check it doesn't exists702 *703 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).704 * @param xmldb_index $xmldb_intex Index object (full specs are required).705 * @return void706 */707 public function add_index($xmldb_table, $xmldb_intex) {708 if (!$this->table_exists($xmldb_table)) {709 throw new ddl_table_missing_exception($xmldb_table->getName());710 }711 // Check index doesn't exist712 if ($this->index_exists($xmldb_table, $xmldb_intex)) {713 throw new ddl_exception('ddlunknownerror', null,714 'Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .715 ' already exists. Create skipped');716 }717 if (!$sqlarr = $this->generator->getAddIndexSQL($xmldb_table, $xmldb_intex)) {718 throw new ddl_exception('ddlunknownerror', null, 'add_index sql not generated');719 }720 try {721 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));722 } catch (ddl_change_structure_exception $e) {723 // There could be a problem with the index length related to the row format of the table.724 // If we are using utf8mb4 and the row format is 'compact' or 'redundant' then we need to change it over to725 // 'compressed' or 'dynamic'.726 if (method_exists($this->mdb, 'convert_table_row_format')) {727 $this->mdb->convert_table_row_format($xmldb_table->getName());728 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));729 } else {730 // It's some other problem that we are currently not handling.731 throw $e;732 }733 }734 }735 /**736 * This function will drop the index in the table passed as arguments737 * Before dropping the index, the function will check it exists738 *739 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).740 * @param xmldb_index $xmldb_intex Index object (full specs are required).741 * @return void742 */743 public function drop_index($xmldb_table, $xmldb_intex) {744 if (!$this->table_exists($xmldb_table)) {745 throw new ddl_table_missing_exception($xmldb_table->getName());746 }747 // Check index exists748 if (!$this->index_exists($xmldb_table, $xmldb_intex)) {749 throw new ddl_exception('ddlunknownerror', null,750 'Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .751 ' does not exist. Drop skipped');752 }753 if (!$sqlarr = $this->generator->getDropIndexSQL($xmldb_table, $xmldb_intex)) {754 throw new ddl_exception('ddlunknownerror', null, 'drop_index sql not generated');755 }756 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));757 }758 /**759 * This function will rename the index in the table passed as arguments760 * Before renaming the index, the function will check it exists761 * Experimental. Shouldn't be used at all!762 *763 * @param xmldb_table $xmldb_table Table object (just the name is mandatory).764 * @param xmldb_index $xmldb_intex Index object (full specs are required).765 * @param string $newname New name of the index.766 * @return void767 */768 public function rename_index($xmldb_table, $xmldb_intex, $newname) {769 debugging('rename_index() is one experimental feature. You must not use it in production!', DEBUG_DEVELOPER);770 // Check newname isn't empty771 if (!$newname) {772 throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');773 }774 // Check index exists775 if (!$this->index_exists($xmldb_table, $xmldb_intex)) {776 throw new ddl_exception('ddlunknownerror', null,777 'Index ' . $xmldb_table->getName() . '->' . $xmldb_intex->getName() .778 ' does not exist. Rename skipped');779 }780 if (!$sqlarr = $this->generator->getRenameIndexSQL($xmldb_table, $xmldb_intex, $newname)) {781 throw new ddl_exception('ddlunknownerror', null, 'Some DBs do not support index renaming (MySQL). Rename skipped');782 }783 $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));784 }785 /**786 * Get the list of install.xml files.787 *788 * @return array789 */790 public function get_install_xml_files(): array {791 global $CFG;792 require_once($CFG->libdir.'/adminlib.php');793 $files = [];794 $dbdirs = get_db_directories();795 foreach ($dbdirs as $dbdir) {796 $filename = "{$dbdir}/install.xml";797 if (file_exists($filename)) {798 $files[] = $filename;799 }800 }801 return $files;802 }803 /**804 * Reads the install.xml files for Moodle core and modules and returns an array of805 * xmldb_structure object with xmldb_table from these files.806 * @return xmldb_structure schema from install.xml files807 */808 public function get_install_xml_schema() {809 global $CFG;810 require_once($CFG->libdir.'/adminlib.php');811 $schema = new xmldb_structure('export');812 $schema->setVersion($CFG->version);813 foreach ($this->get_install_xml_files() as $filename) {814 $xmldb_file = new xmldb_file($filename);815 if (!$xmldb_file->loadXMLStructure()) {816 continue;817 }818 $structure = $xmldb_file->getStructure();819 $tables = $structure->getTables();820 foreach ($tables as $table) {821 $table->setPrevious(null);822 $table->setNext(null);823 $schema->addTable($table);824 }825 }826 return $schema;827 }828 /**829 * Checks the database schema against a schema specified by an xmldb_structure object830 * @param xmldb_structure $schema export schema describing all known tables831 * @param array $options832 * @return array keyed by table name with array of difference messages as values833 */834 public function check_database_schema(xmldb_structure $schema, array $options = null) {835 $alloptions = array(836 'extratables' => true,837 'missingtables' => true,838 'extracolumns' => true,839 'missingcolumns' => true,840 'changedcolumns' => true,841 );842 $typesmap = array(843 'I' => XMLDB_TYPE_INTEGER,844 'R' => XMLDB_TYPE_INTEGER,845 'N' => XMLDB_TYPE_NUMBER,846 'F' => XMLDB_TYPE_NUMBER, // Nobody should be using floats!847 'C' => XMLDB_TYPE_CHAR,848 'X' => XMLDB_TYPE_TEXT,849 'B' => XMLDB_TYPE_BINARY,850 'T' => XMLDB_TYPE_TIMESTAMP,851 'D' => XMLDB_TYPE_DATETIME,852 );853 $options = (array)$options;854 $options = array_merge($alloptions, $options);855 // Note: the error descriptions are not supposed to be localised,856 // it is intended for developers and skilled admins only.857 $errors = array();858 /** @var string[] $dbtables */859 $dbtables = $this->mdb->get_tables(false);860 /** @var xmldb_table[] $tables */861 $tables = $schema->getTables();862 foreach ($tables as $table) {863 $tablename = $table->getName();864 if ($options['missingtables']) {865 // Missing tables are a fatal problem.866 if (empty($dbtables[$tablename])) {867 $errors[$tablename][] = "table is missing";868 continue;869 }870 }871 /** @var database_column_info[] $dbfields */872 $dbfields = $this->mdb->get_columns($tablename, false);873 /** @var xmldb_field[] $fields */874 $fields = $table->getFields();875 foreach ($fields as $field) {876 $fieldname = $field->getName();877 if (empty($dbfields[$fieldname])) {878 if ($options['missingcolumns']) {879 // Missing columns are a fatal problem.880 $errors[$tablename][] = "column '$fieldname' is missing";881 }882 } else if ($options['changedcolumns']) {883 $dbfield = $dbfields[$fieldname];884 if (!isset($typesmap[$dbfield->meta_type])) {885 $errors[$tablename][] = "column '$fieldname' has unsupported type '$dbfield->meta_type'";886 } else {887 $dbtype = $typesmap[$dbfield->meta_type];888 $type = $field->getType();889 if ($type == XMLDB_TYPE_FLOAT) {890 $type = XMLDB_TYPE_NUMBER;...

Full Screen

Full Screen

Ignore.php

Source:Ignore.php Github

copy

Full Screen

...28 break;29 30 case 'list':31 $names = "";32 if(empty($this->main->list->get($sender->getName()))){33 $sender->sendMessage("§3IgnoredPlayers: §7$names");34 return false;35 }36 37 $list = $this->main->list->get($sender->getName());38 foreach(array_keys($list) as $key){39 $name = $list[$key];40 $names .= $name . ", ";41 }42 43 $sender->sendMessage("§3IgnoredPlayers: §7$names");44 break;45 46 case 'add':47 if(!isset($args[1])){48 $sender->sendMessage('§cUsage: /ignore add [player]');49 return false;50 }51 52 if($this->main->getServer()->getPlayer($args[1]) === null or !$this->main->getServer()->getPlayer($args[1])->isOnline()){53 $sender->sendMessage('§cPlayer not found');54 return false;55 }56 57 $player = $this->main->getServer()->getPlayer($args[1]);58 59 if($player->getName() == $sender->getName()){60 $sender->sendMessage('§cYou cannot ignore yourself');61 return false;62 }63 64 if(empty($this->main->list->get($sender->getName()))){65 $list[] = $player->getName();66 $this->main->list->set($sender->getName(), $list);67 $this->main->list->save();68 $sender->sendMessage('§cYou are now ignoring ' . $player->getName());69 return false;70 }71 72 if(in_array($player->getName(), $this->main->list->get($sender->getName()))){73 $sender->sendMessage('§cYou are already ignoring ' . $player->getName());74 return false;75 }76 77 $list = $this->main->list->get($sender->getName());78 $list[] = $player->getName();79 $this->main->list->set($sender->getName(), $list);80 $this->main->list->save();81 $sender->sendMessage('§cYou are now ignoring ' . $player->getName());82 break;83 84 case 'remove':85 if(!isset($args[1])){86 $sender->sendMessage('§cUsage: /ignore remove [player]');87 return false;88 }89 90 if($this->main->getServer()->getPlayer($args[1]) === null or !$this->main->getServer()->getPlayer($args[1])->isOnline()){91 $sender->sendMessage('§cPlayer not found');92 return false;93 }94 95 $player = $this->main->getServer()->getPlayer($args[1]);96 97 if(empty($this->main->list->get($sender->getName()))){98 $sender->sendMessage('§cYou are not ignoring ' . $player->getName());99 return false;100 }101 102 if(!in_array($player->getName(), $this->main->list->get($sender->getName()))){103 $sender->sendMessage('§cYou are not ignoring ' . $player->getName());104 return false;105 }106 107 $list = $this->main->list->get($sender->getName());108 $key = array_search($player->getName(), $list);109 array_splice($list, $key, 1);110 $this->main->list->set($sender->getName(), $list);111 $this->main->list->save();112 $sender->sendMessage('§cYou are not longer ignoring ' . $player->getName());113 break;114 115 default:116 $sender->sendMessage('§cInvalid argument given. Do /ignore help for more information');117 break;118 }119 }120 public function getPlugin() : Plugin {121 return $this->main;122 }123}...

Full Screen

Full Screen

getName

Using AI Code Generation

copy

Full Screen

1echo $obj->getName();2echo $obj->getName();3echo $obj->getName();4echo $obj->getName();5echo $obj->getName();6echo $obj->getName();7echo $obj->getName();8echo $obj->getName();9echo $obj->getName();10echo $obj->getName();11echo $obj->getName();12echo $obj->getName();13echo $obj->getName();14echo $obj->getName();15echo $obj->getName();16echo $obj->getName();17echo $obj->getName();18echo $obj->getName();19echo $obj->getName();20echo $obj->getName();21echo $obj->getName();22echo $obj->getName();

Full Screen

Full Screen

getName

Using AI Code Generation

copy

Full Screen

1$are = new are();2echo $are->getName();3$are = new are();4echo $are->getName();5$are = new are();6echo $are->getName();7{8 public static $name = "Are";9 public function getName()10 {11 return self::$name;12 }13}14$are = new are();15echo $are->getName();16$are = new are();17echo $are->getName();18$are = new are();19echo $are->getName();20$are = new are();21echo $are->getName();22{23 public static $name = "Are";24 public function getName()25 {26 return self::$name;27 }28}29$are = new are();30echo $are->getName();31$are = new are();32echo $are->getName();

Full Screen

Full Screen

getName

Using AI Code Generation

copy

Full Screen

1$are = new are();2echo $are->getName();3$are = new are();4echo $are->getName();5$are = new are();6echo $are->getName();7$are = new are();8echo $are->getName();9$are = new are();10echo $are->getName();11$are = new are();12echo $are->getName();13$are = new are();14echo $are->getName();15$are = new are();16echo $are->getName();17$are = new are();18echo $are->getName();19$are = new are();20echo $are->getName();21$are = new are();22echo $are->getName();23$are = new are();24echo $are->getName();25$are = new are();26echo $are->getName();27$are = new are();28echo $are->getName();29$are = new are();30echo $are->getName();31$are = new are();32echo $are->getName();33$are = new are();34echo $are->getName();

Full Screen

Full Screen

getName

Using AI Code Generation

copy

Full Screen

1$object = new Area();2echo $object->getName();3$object = new Area();4echo $object->getName();5$object = new Area();6echo $object->getName();7$object = new Area();8echo $object->getName();9$object = new Area();10echo $object->getName();11$object = new Area();12echo $object->getName();13$object = new Area();14echo $object->getName();15$object = new Area();16echo $object->getName();17$object = new Area();18echo $object->getName();19$object = new Area();20echo $object->getName();21$object = new Area();22echo $object->getName();23$object = new Area();24echo $object->getName();25$object = new Area();26echo $object->getName();27$object = new Area();28echo $object->getName();29$object = new Area();30echo $object->getName();31$object = new Area();32echo $object->getName();33$object = new Area();34echo $object->getName();

Full Screen

Full Screen

getName

Using AI Code Generation

copy

Full Screen

1echo $obj->getName();2echo $obj->getName();3class A{4 public function getName(){5 return "Hello";6 }7}8$obj = new A();9echo $obj->getName();10class A{11 public function getName(){12 return "Hello";13 }14}15include "A.php";16$obj = new A();17echo $obj->getName();18class A{19 public function getName(){20 return "Hello";21 }22}23class B extends A{24 public function getAge(){25 return 20;26 }27}28$obj = new B();29echo $obj->getName();30echo $obj->getAge();

Full Screen

Full Screen

getName

Using AI Code Generation

copy

Full Screen

1echo $obj->getName();2$obj->setName("PHP");3Syntax: include("file path");4include("1.php");5include("2.php");6Syntax: include_once("file path");7include_once("1.php");8include_once("2.php");9Syntax: require("file path");10require("1

Full Screen

Full Screen

getName

Using AI Code Generation

copy

Full Screen

1echo $obj->getName();2$this->method_name();3{4 public $name;5 public function __construct($name)6 {7 $this->name = $name;8 }9 public function getStudentDetails()10 {11 echo "Name is: " . $this->name;12 }13 public function getStudentName()14 {15 $this->getStudentDetails();16 }17}18$obj = new Student("John");19$obj->getStudentName();20$obj = new ClassName();21$obj->method_name();22{23 public $name;24 public function __construct($name)25 {26 $this->name = $name;27 }28 public function getStudentDetails()29 {30 echo "Name is: " . $this->name;31 }32}33{34 public function getStudentName()35 {36 $obj = new Student("John");37 $obj->getStudentDetails();38 }39}40$obj = new Teacher();41$obj->getStudentName();42ClassName::method_name();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful