/** * Checks to see if all of the indexes are in place for the BO's table, creates those that are missing. * * @since 1.1 */ private function checkIndexes() { self::$logger->debug('>>checkIndexes()'); $indexNames = $this->getIndexes(); // process unique keys foreach ($this->BO->getUniqueAttributes() as $prop) { // check for composite indexes if (mb_strpos($prop, '+')) { $attributes = explode('+', $prop); $index_exists = false; foreach ($indexNames as $index) { if ($attributes[0] . '_' . $attributes[1] . '_unq_idx' == $index) { $index_exists = true; } if (count($attributes) == 3) { if ($attributes[0] . '_' . $attributes[1] . '_' . $attributes[2] . '_unq_idx' == $index) { $index_exists = true; } } } if (!$index_exists) { if (count($attributes) == 3) { $this->BO->createUniqueIndex($attributes[0], $attributes[1], $attributes[2]); } else { $this->BO->createUniqueIndex($attributes[0], $attributes[1]); } } } else { $index_exists = false; foreach ($indexNames as $index) { if ($prop . '_unq_idx' == $index) { $index_exists = true; } } if (!$index_exists) { $this->createUniqueIndex($prop); } } } // process foreign-key indexes // get the class attributes $reflection = new ReflectionClass(get_class($this->BO)); $properties = $reflection->getProperties(); foreach ($properties as $propObj) { $propName = $propObj->name; $prop = $this->BO->getPropObject($propName); if ($prop instanceof Relation) { if ($prop->getRelationType() == 'MANY-TO-ONE') { $indexExists = false; foreach ($indexNames as $index) { if ($this->BO->getTableName() . '_' . $propName . '_fk_idx' == $index) { $indexExists = true; } } if (!$indexExists) { $this->createForeignIndex($propName, $prop->getRelatedClass(), $prop->getRelatedClassField()); } } if ($prop->getRelationType() == 'MANY-TO-MANY') { $lookup = $prop->getLookup(); if ($lookup != null) { try { $lookupIndexNames = $lookup->getIndexes(); // handle index check/creation on left side of Relation $indexExists = false; foreach ($lookupIndexNames as $index) { if ($lookup->getTableName() . '_leftID_fk_idx' == $index) { $indexExists = true; } } if (!$indexExists) { $lookup->createForeignIndex('leftID', $prop->getRelatedClass('left'), 'OID'); } // handle index check/creation on right side of Relation $indexExists = false; foreach ($lookupIndexNames as $index) { if ($lookup->getTableName() . '_rightID_fk_idx' == $index) { $indexExists = true; } } if (!$indexExists) { $lookup->createForeignIndex('rightID', $prop->getRelatedClass('right'), 'OID'); } } catch (AlphaException $e) { self::$logger->error($e->getMessage()); } } } } } self::$logger->debug('<<checkIndexes'); }
/** * Checks to see if all of the indexes are in place for the BO's table, creates those that are missing. * * @since 1.2 */ private function checkIndexes() { self::$logger->debug('>>checkIndexes()'); $indexNames = $this->BO->getIndexes(); // process unique keys foreach ($this->BO->getUniqueAttributes() as $prop) { // check for composite indexes if (mb_strpos($prop, '+')) { $attributes = explode('+', $prop); $index_exists = false; foreach ($indexNames as $index) { if ($attributes[0] . '_' . $attributes[1] . '_unq_idx' == $index) { $index_exists = true; } if (count($attributes) == 3) { if ($attributes[0] . '_' . $attributes[1] . '_' . $attributes[2] . '_unq_idx' == $index) { $index_exists = true; } } } if (!$index_exists) { if (count($attributes) == 3) { $this->BO->createUniqueIndex($attributes[0], $attributes[1], $attributes[2]); } else { $this->BO->createUniqueIndex($attributes[0], $attributes[1]); } } } else { $index_exists = false; foreach ($indexNames as $index) { if ($prop . '_unq_idx' == $index) { $index_exists = true; } } if (!$index_exists) { $this->createUniqueIndex($prop); } } } self::$logger->debug('<<checkIndexes'); }