| @@ 2273-2333 (lines=61) @@ | ||
| 2270 | * |
|
| 2271 | * @see Alpha\Model\ActiveRecordProviderInterface::isTableOverloaded() |
|
| 2272 | */ |
|
| 2273 | public function isTableOverloaded() |
|
| 2274 | { |
|
| 2275 | self::$logger->debug('>>isTableOverloaded()'); |
|
| 2276 | ||
| 2277 | $reflection = new ReflectionClass($this->BO); |
|
| 2278 | $classname = $reflection->getShortName(); |
|
| 2279 | $tablename = ucfirst($this->BO->getTableName()); |
|
| 2280 | ||
| 2281 | // use reflection to check to see if we are dealing with a persistent type (e.g. DEnum) which are never overloaded |
|
| 2282 | $implementedInterfaces = $reflection->getInterfaces(); |
|
| 2283 | ||
| 2284 | foreach ($implementedInterfaces as $interface) { |
|
| 2285 | if ($interface->name == 'Alpha\Model\Type\TypeInterface') { |
|
| 2286 | self::$logger->debug('<<isTableOverloaded [false]'); |
|
| 2287 | ||
| 2288 | return false; |
|
| 2289 | } |
|
| 2290 | } |
|
| 2291 | ||
| 2292 | if ($classname != $tablename) { |
|
| 2293 | // loop over all BOs to see if there is one using the same table as this BO |
|
| 2294 | ||
| 2295 | $BOclasses = ActiveRecord::getBOClassNames(); |
|
| 2296 | ||
| 2297 | foreach ($BOclasses as $BOclassName) { |
|
| 2298 | $reflection = new ReflectionClass($BOclassName); |
|
| 2299 | $classname = $reflection->getShortName(); |
|
| 2300 | if ($tablename == $classname) { |
|
| 2301 | self::$logger->debug('<<isTableOverloaded [true]'); |
|
| 2302 | ||
| 2303 | return true; |
|
| 2304 | } |
|
| 2305 | } |
|
| 2306 | throw new BadTableNameException('The table name ['.$tablename.'] for the class ['.$classname.'] is invalid as it does not match a BO definition in the system!'); |
|
| 2307 | self::$logger->debug('<<isTableOverloaded [false]'); |
|
| 2308 | ||
| 2309 | return false; |
|
| 2310 | } else { |
|
| 2311 | // check to see if there is already a "classname" column in the database for this BO |
|
| 2312 | ||
| 2313 | $query = 'SHOW COLUMNS FROM '.$this->BO->getTableName(); |
|
| 2314 | ||
| 2315 | $result = self::getConnection()->query($query); |
|
| 2316 | ||
| 2317 | if ($result) { |
|
| 2318 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 2319 | if ('classname' == $row['Field']) { |
|
| 2320 | self::$logger->debug('<<isTableOverloaded [true]'); |
|
| 2321 | ||
| 2322 | return true; |
|
| 2323 | } |
|
| 2324 | } |
|
| 2325 | } else { |
|
| 2326 | self::$logger->warn('Error during show columns ['.self::getConnection()->error.']'); |
|
| 2327 | } |
|
| 2328 | ||
| 2329 | self::$logger->debug('<<isTableOverloaded [false]'); |
|
| 2330 | ||
| 2331 | return false; |
|
| 2332 | } |
|
| 2333 | } |
|
| 2334 | ||
| 2335 | /** |
|
| 2336 | * (non-PHPdoc). |
|
| @@ 2239-2298 (lines=60) @@ | ||
| 2236 | * |
|
| 2237 | * @see Alpha\Model\ActiveRecordProviderInterface::isTableOverloaded() |
|
| 2238 | */ |
|
| 2239 | public function isTableOverloaded() |
|
| 2240 | { |
|
| 2241 | self::$logger->debug('>>isTableOverloaded()'); |
|
| 2242 | ||
| 2243 | $reflection = new ReflectionClass($this->BO); |
|
| 2244 | $classname = $reflection->getShortName(); |
|
| 2245 | $tablename = ucfirst($this->BO->getTableName()); |
|
| 2246 | ||
| 2247 | // use reflection to check to see if we are dealing with a persistent type (e.g. DEnum) which are never overloaded |
|
| 2248 | $implementedInterfaces = $reflection->getInterfaces(); |
|
| 2249 | ||
| 2250 | foreach ($implementedInterfaces as $interface) { |
|
| 2251 | if ($interface->name == 'Alpha\Model\Type\TypeInterface') { |
|
| 2252 | self::$logger->debug('<<isTableOverloaded [false]'); |
|
| 2253 | ||
| 2254 | return false; |
|
| 2255 | } |
|
| 2256 | } |
|
| 2257 | ||
| 2258 | if ($classname != $tablename) { |
|
| 2259 | // loop over all BOs to see if there is one using the same table as this BO |
|
| 2260 | ||
| 2261 | $BOclasses = ActiveRecord::getBOClassNames(); |
|
| 2262 | ||
| 2263 | foreach ($BOclasses as $BOclassName) { |
|
| 2264 | $reflection = new ReflectionClass($BOclassName); |
|
| 2265 | $classname = $reflection->getShortName(); |
|
| 2266 | if ($tablename == $classname) { |
|
| 2267 | self::$logger->debug('<<isTableOverloaded [true]'); |
|
| 2268 | ||
| 2269 | return true; |
|
| 2270 | } |
|
| 2271 | } |
|
| 2272 | throw new BadTableNameException('The table name ['.$tablename.'] for the class ['.$classname.'] is invalid as it does not match a BO definition in the system!'); |
|
| 2273 | self::$logger->debug('<<isTableOverloaded [false]'); |
|
| 2274 | ||
| 2275 | return false; |
|
| 2276 | } else { |
|
| 2277 | // check to see if there is already a "classname" column in the database for this BO |
|
| 2278 | $sqlQuery = 'PRAGMA table_info('.$this->BO->getTableName().')'; |
|
| 2279 | $result = self::getConnection()->query($sqlQuery); |
|
| 2280 | $this->BO->setLastQuery($sqlQuery); |
|
| 2281 | ||
| 2282 | if (!$result) { |
|
| 2283 | self::$logger->warn('Error during pragma table info lookup ['.self::getLastDatabaseError().']'); |
|
| 2284 | } else { |
|
| 2285 | while ($row = $result->fetchArray(SQLITE3_ASSOC)) { |
|
| 2286 | if ('classname' == $row['name']) { |
|
| 2287 | self::$logger->debug('<<isTableOverloaded [true]'); |
|
| 2288 | ||
| 2289 | return true; |
|
| 2290 | } |
|
| 2291 | } |
|
| 2292 | } |
|
| 2293 | ||
| 2294 | self::$logger->debug('<<isTableOverloaded [false]'); |
|
| 2295 | ||
| 2296 | return false; |
|
| 2297 | } |
|
| 2298 | } |
|
| 2299 | ||
| 2300 | /** |
|
| 2301 | * (non-PHPdoc). |
|