parent
3bad4d138e
commit
7080a32650
10 changed files with 252 additions and 6 deletions
@ -0,0 +1,83 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* This class is used to test database is well-constructed. |
||||
*/ |
||||
class FreshRSS_DatabaseDAO extends Minz_ModelPdo { |
||||
public function tablesAreCorrect() { |
||||
$sql = 'SHOW TABLES'; |
||||
$stm = $this->bd->prepare($sql); |
||||
$stm->execute(); |
||||
$res = $stm->fetchAll(PDO::FETCH_ASSOC); |
||||
|
||||
$tables = array( |
||||
$this->prefix . 'category' => false, |
||||
$this->prefix . 'feed' => false, |
||||
$this->prefix . 'entry' => false, |
||||
); |
||||
foreach ($res as $value) { |
||||
$tables[array_pop($value)] = true; |
||||
} |
||||
|
||||
return count(array_keys($tables, true, true)) == count($tables); |
||||
} |
||||
|
||||
public function getSchema($table) { |
||||
$sql = 'DESC ' . $this->prefix . $table; |
||||
$stm = $this->bd->prepare($sql); |
||||
$stm->execute(); |
||||
|
||||
return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC)); |
||||
} |
||||
|
||||
public function checkTable($table, $schema) { |
||||
$columns = $this->getSchema($table); |
||||
|
||||
$ok = (count($columns) == count($schema)); |
||||
foreach ($columns as $c) { |
||||
$ok &= in_array($c['name'], $schema); |
||||
} |
||||
|
||||
return $ok; |
||||
} |
||||
|
||||
public function categoryIsCorrect() { |
||||
return $this->checkTable('category', array( |
||||
'id', 'name' |
||||
)); |
||||
} |
||||
|
||||
public function feedIsCorrect() { |
||||
return $this->checkTable('feed', array( |
||||
'id', 'url', 'category', 'name', 'website', 'description', 'lastUpdate', |
||||
'priority', 'pathEntries', 'httpAuth', 'error', 'keep_history', 'ttl', |
||||
'cache_nbEntries', 'cache_nbUnreads' |
||||
)); |
||||
} |
||||
|
||||
public function entryIsCorrect() { |
||||
return $this->checkTable('entry', array( |
||||
'id', 'guid', 'title', 'author', 'content_bin', 'link', 'date', 'is_read', |
||||
'is_favorite', 'id_feed', 'tags' |
||||
)); |
||||
} |
||||
|
||||
public function daoToSchema($dao) { |
||||
return array( |
||||
'name' => $dao['Field'], |
||||
'type' => strtolower($dao['Type']), |
||||
'notnull' => (bool)$dao['Null'], |
||||
'default' => $dao['Default'], |
||||
); |
||||
} |
||||
|
||||
public function listDaoToSchema($listDAO) { |
||||
$list = array(); |
||||
|
||||
foreach ($listDAO as $dao) { |
||||
$list[] = $this->daoToSchema($dao); |
||||
} |
||||
|
||||
return $list; |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* This class is used to test database is well-constructed (SQLite). |
||||
*/ |
||||
class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { |
||||
public function tablesAreCorrect() { |
||||
$sql = 'SELECT name FROM sqlite_master WHERE type="table"'; |
||||
$stm = $this->bd->prepare($sql); |
||||
$stm->execute(); |
||||
$res = $stm->fetchAll(PDO::FETCH_ASSOC); |
||||
|
||||
$tables = array( |
||||
'category' => false, |
||||
'feed' => false, |
||||
'entry' => false, |
||||
); |
||||
foreach ($res as $value) { |
||||
$tables[$value['name']] = true; |
||||
} |
||||
|
||||
return count(array_keys($tables, true, true)) == count($tables); |
||||
} |
||||
|
||||
public function getSchema($table) { |
||||
$sql = 'PRAGMA table_info(' . $table . ')'; |
||||
$stm = $this->bd->prepare($sql); |
||||
$stm->execute(); |
||||
|
||||
return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC)); |
||||
} |
||||
|
||||
public function entryIsCorrect() { |
||||
return $this->checkTable('entry', array( |
||||
'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'is_read', |
||||
'is_favorite', 'id_feed', 'tags' |
||||
)); |
||||
} |
||||
|
||||
public function daoToSchema($dao) { |
||||
return array( |
||||
'name' => $dao['name'], |
||||
'type' => strtolower($dao['type']), |
||||
'notnull' => $dao['notnull'] === '1' ? true : false, |
||||
'default' => $dao['dflt_value'], |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
<?php $this->partial('aside_configure'); ?> |
||||
|
||||
<div class="post"> |
||||
<a href="<?php echo _url('index', 'index'); ?>"><?php echo _t('back_to_rss_feeds'); ?></a>
|
||||
|
||||
<h2><?php echo _t('admin.check_install.php'); ?></h2>
|
||||
|
||||
<?php foreach ($this->status_php as $key => $status) { ?> |
||||
<p class="alert <?php echo $status ? 'alert-success' : 'alert-error'; ?>">
|
||||
<?php echo _t('admin.check_install.' . $key . '.' . ($status ? 'ok' : 'nok')); ?> |
||||
</p> |
||||
<?php } ?> |
||||
|
||||
<h2><?php echo _t('admin.check_install.files'); ?></h2>
|
||||
|
||||
<?php foreach ($this->status_files as $key => $status) { ?> |
||||
<p class="alert <?php echo $status ? 'alert-success' : 'alert-error'; ?>">
|
||||
<?php echo _t('admin.check_install.' . $key . '.' . ($status ? 'ok' : 'nok')); ?> |
||||
</p> |
||||
<?php } ?> |
||||
|
||||
<h2><?php echo _t('admin.check_install.database'); ?></h2>
|
||||
|
||||
<?php foreach ($this->status_database as $key => $status) { ?> |
||||
<p class="alert <?php echo $status ? 'alert-success' : 'alert-error'; ?>">
|
||||
<?php echo _t('admin.check_install.' . $key . '.' . ($status ? 'ok' : 'nok')); ?> |
||||
</p> |
||||
<?php } ?> |
||||
|
||||
</div> |
Loading…
Reference in new issue