Exemplo n.º 1
0
 /**
  * check the DB for expected content
  *
  * @param Fooman_Common_Model_Selftester $selftester
  * @param                                $fields
  * @param                                $installer
  * @param                                $localError
  *
  * @return bool
  */
 protected function _dbCheckDbRow(Fooman_Common_Model_Selftester $selftester, $fields, $installer, $localError)
 {
     try {
         $where = array();
         foreach ($fields[2] as $key => $value) {
             $where[] = "`" . $key . "`='" . $value . "'";
         }
         $sql = "SELECT * FROM `{$installer->getTable($fields[1])}` WHERE " . implode(' AND ', $where) . ";";
         $result = $installer->getConnection()->fetchOne($sql);
         if (!$result) {
             throw new Exception(sprintf('Did not find content in %s', $installer->getTable($fields[1])));
         }
         $selftester->messages[] = "[OK] Content " . $fields[1] . "";
     } catch (Exception $e) {
         if ($selftester->shouldFix()) {
             $selftester->messages[] = "Attempting fix for content in " . $fields[1] . "";
             try {
                 $installer->getConnection()->insert($installer->getTable($fields[1]), $fields[2]);
                 $selftester->messages[] = "[FIX OK] content in " . $fields[1] . " fixed";
             } catch (Exception $e) {
                 $selftester->messages[] = "[FAILED] fixing content in " . $fields[1] . "";
                 $this->_dbOkay = false;
                 $selftester->messages[] = $e->getMessage();
                 $localError = true;
             }
         } else {
             $selftester->messages[] = "[FAILED] content in " . $fields[1] . "";
             $this->_dbOkay = false;
             $selftester->messages[] = "[ERR] " . $e->getMessage();
             $localError = true;
         }
     }
     return $localError;
 }
Exemplo n.º 2
0
 /**
  * check the DB for expected content
  *
  * @param Fooman_Common_Model_Selftester $selftester
  * @param                                $fields
  * @param                                $installer
  * @param                                $localError
  *
  * @return bool
  */
 protected function _dbCheckDbRow(Fooman_Common_Model_Selftester $selftester, $fields, $installer, $localError)
 {
     try {
         $select = $installer->getConnection()->select()->from($installer->getTable($fields[1]));
         $bind = array();
         foreach ($fields[2] as $key => $value) {
             $bind[$key] = $value;
             $select->where($installer->getConnection()->quoteIdentifier($key) . '= :' . $key);
         }
         $result = $installer->getConnection()->fetchRow($select, $bind);
         if (!$result) {
             throw new Exception(sprintf('Did not find content in %s', $installer->getTable($fields[1])));
         }
         $selftester->messages[] = "[OK] Content " . $fields[1] . "";
     } catch (Exception $e) {
         if ($selftester->shouldFix()) {
             $selftester->messages[] = "Attempting fix for content in " . $fields[1] . "";
             try {
                 $installer->getConnection()->insert($installer->getTable($fields[1]), $fields[2]);
                 $selftester->messages[] = "[FIX OK] content in " . $fields[1] . " fixed";
             } catch (Exception $e) {
                 $selftester->messages[] = "[FAILED] fixing content in " . $fields[1] . "";
                 $this->_dbOkay = false;
                 $selftester->messages[] = $e->getMessage();
                 $localError = true;
             }
         } else {
             $selftester->messages[] = "[FAILED] content in " . $fields[1] . "";
             $this->_dbOkay = false;
             $selftester->messages[] = "[ERR] " . $e->getMessage();
             $localError = true;
         }
     }
     return $localError;
 }
Exemplo n.º 3
0
 /**
  * check the DB for an expected table column
  *
  * @param Fooman_Common_Model_Selftester $selftester
  * @param                                $field
  * @param                                $installer
  * @param                                $localError
  *
  * @return bool
  */
 protected function _dbCheckSqlColumn(Fooman_Common_Model_Selftester $selftester, $field, $installer, $localError)
 {
     try {
         if (!$installer->getConnection()->tableColumnExists($installer->getTable($field[1]), $field[2])) {
             throw new Exception(sprintf('Did not find column %s in table %s', $field[2], $installer->getTable($field[1])));
         }
         $selftester->messages[] = "[OK] column " . $field[2] . "";
     } catch (Exception $e) {
         if ($selftester->shouldFix()) {
             $selftester->messages[] = "Attempting fix for column " . $field[2] . "";
             try {
                 $installer->getConnection()->addColumn($installer->getTable($field[1]), $field[2], $field[3]);
                 $selftester->messages[] = "[FIX OK] column " . $field[2] . " fixed";
             } catch (Exception $e) {
                 $selftester->messages[] = "[FAILED] fixing column " . $field[2] . "";
                 $this->_dbOkay = false;
                 $selftester->messages[] = $e->getMessage();
                 $localError = true;
             }
         } else {
             $selftester->messages[] = "[FAILED] column " . $field[2] . "";
             $this->_dbOkay = false;
             $selftester->messages[] = "[ERR] " . $e->getMessage();
             $localError = true;
         }
     }
     return $localError;
 }