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