| @@ 1905-1965 (lines=61) @@ | ||
| 1902 | * |
|
| 1903 | * @see Alpha\Model\ActiveRecordProviderInterface::findMissingFields() |
|
| 1904 | */ |
|
| 1905 | public function findMissingFields() |
|
| 1906 | { |
|
| 1907 | self::$logger->debug('>>findMissingFields()'); |
|
| 1908 | ||
| 1909 | $missingFields = array(); |
|
| 1910 | $matchCount = 0; |
|
| 1911 | ||
| 1912 | $sqlQuery = 'SHOW COLUMNS FROM '.$this->BO->getTableName(); |
|
| 1913 | ||
| 1914 | $result = self::getConnection()->query($sqlQuery); |
|
| 1915 | ||
| 1916 | $this->BO->setLastQuery($sqlQuery); |
|
| 1917 | ||
| 1918 | // get the class attributes |
|
| 1919 | $reflection = new ReflectionClass(get_class($this->BO)); |
|
| 1920 | $properties = $reflection->getProperties(); |
|
| 1921 | ||
| 1922 | foreach ($properties as $propObj) { |
|
| 1923 | $propName = $propObj->name; |
|
| 1924 | if (!in_array($propName, $this->BO->getTransientAttributes())) { |
|
| 1925 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 1926 | if ($propName == $row['Field']) { |
|
| 1927 | ++$matchCount; |
|
| 1928 | break; |
|
| 1929 | } |
|
| 1930 | } |
|
| 1931 | $result->data_seek(0); |
|
| 1932 | } else { |
|
| 1933 | ++$matchCount; |
|
| 1934 | } |
|
| 1935 | ||
| 1936 | if ($matchCount == 0) { |
|
| 1937 | array_push($missingFields, $propName); |
|
| 1938 | } else { |
|
| 1939 | $matchCount = 0; |
|
| 1940 | } |
|
| 1941 | } |
|
| 1942 | ||
| 1943 | // check for the "classname" field in overloaded tables |
|
| 1944 | if ($this->BO->isTableOverloaded()) { |
|
| 1945 | $foundMatch = false; |
|
| 1946 | ||
| 1947 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 1948 | if ('classname' == $row['Field']) { |
|
| 1949 | $foundMatch = true; |
|
| 1950 | break; |
|
| 1951 | } |
|
| 1952 | } |
|
| 1953 | if (!$foundMatch) { |
|
| 1954 | array_push($missingFields, 'classname'); |
|
| 1955 | } |
|
| 1956 | } |
|
| 1957 | ||
| 1958 | if (!$result) { |
|
| 1959 | throw new AlphaException('Failed to access the system database correctly, error is ['.self::getConnection()->error.']'); |
|
| 1960 | } |
|
| 1961 | ||
| 1962 | self::$logger->debug('<<findMissingFields ['.var_export($missingFields, true).']'); |
|
| 1963 | ||
| 1964 | return $missingFields; |
|
| 1965 | } |
|
| 1966 | ||
| 1967 | /** |
|
| 1968 | * (non-PHPdoc). |
|
| @@ 1924-1982 (lines=59) @@ | ||
| 1921 | * |
|
| 1922 | * @see Alpha\Model\ActiveRecordProviderInterface::findMissingFields() |
|
| 1923 | */ |
|
| 1924 | public function findMissingFields() |
|
| 1925 | { |
|
| 1926 | self::$logger->debug('>>findMissingFields()'); |
|
| 1927 | ||
| 1928 | $missingFields = array(); |
|
| 1929 | $matchCount = 0; |
|
| 1930 | ||
| 1931 | $sqlQuery = 'PRAGMA table_info('.$this->BO->getTableName().')'; |
|
| 1932 | $result = self::getConnection()->query($sqlQuery); |
|
| 1933 | $this->BO->setLastQuery($sqlQuery); |
|
| 1934 | ||
| 1935 | // get the class attributes |
|
| 1936 | $reflection = new ReflectionClass(get_class($this->BO)); |
|
| 1937 | $properties = $reflection->getProperties(); |
|
| 1938 | ||
| 1939 | foreach ($properties as $propObj) { |
|
| 1940 | $propName = $propObj->name; |
|
| 1941 | if (!in_array($propName, $this->BO->getTransientAttributes())) { |
|
| 1942 | while ($row = $result->fetchArray(SQLITE3_ASSOC)) { |
|
| 1943 | if ($propName == $row['name']) { |
|
| 1944 | ++$matchCount; |
|
| 1945 | break; |
|
| 1946 | } |
|
| 1947 | } |
|
| 1948 | $result->reset(); |
|
| 1949 | } else { |
|
| 1950 | ++$matchCount; |
|
| 1951 | } |
|
| 1952 | ||
| 1953 | if ($matchCount == 0) { |
|
| 1954 | array_push($missingFields, $propName); |
|
| 1955 | } else { |
|
| 1956 | $matchCount = 0; |
|
| 1957 | } |
|
| 1958 | } |
|
| 1959 | ||
| 1960 | // check for the "classname" field in overloaded tables |
|
| 1961 | if ($this->BO->isTableOverloaded()) { |
|
| 1962 | $foundMatch = false; |
|
| 1963 | ||
| 1964 | while ($row = $result->fetchArray(SQLITE3_ASSOC)) { |
|
| 1965 | if ('classname' == $row['name']) { |
|
| 1966 | $foundMatch = true; |
|
| 1967 | break; |
|
| 1968 | } |
|
| 1969 | } |
|
| 1970 | if (!$foundMatch) { |
|
| 1971 | array_push($missingFields, 'classname'); |
|
| 1972 | } |
|
| 1973 | } |
|
| 1974 | ||
| 1975 | if (!$result) { |
|
| 1976 | throw new AlphaException('Failed to access the system database correctly, error is ['.self::getLastDatabaseError().']'); |
|
| 1977 | } |
|
| 1978 | ||
| 1979 | self::$logger->debug('<<findMissingFields ['.var_export($missingFields, true).']'); |
|
| 1980 | ||
| 1981 | return $missingFields; |
|
| 1982 | } |
|
| 1983 | ||
| 1984 | /** |
|
| 1985 | * (non-PHPdoc). |
|