This commit is contained in:
root 2019-09-10 23:37:14 +02:00
Родитель 6e07c5b78c
Коммит 3c22fd5ab4
3 изменённых файлов: 53 добавлений и 9 удалений

Просмотреть файл

@ -5,7 +5,7 @@
<name>Cookbook</name>
<summary>An integrated cookbook using schema.org JSON files as recipes</summary>
<description><![CDATA[A library for all your recipes. It uses JSON files following the schema.org recipe format. To add a recipe to the collection, you can paste in the URL of the recipe, and the provided web page will be parsed and downloaded to whichever folder you specify in the app settings.]]></description>
<version>0.4.0</version>
<version>0.4.1</version>
<licence>agpl</licence>
<author mail="mrzapp@users.noreply.github.com" >Jeppe Zapp</author>
<namespace>Cookbook</namespace>

Просмотреть файл

@ -21,7 +21,7 @@ class RecipeDb {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('cookbook_recipes')
->from('cookbook_recipe')
->where('id = :id');
$qb->setParameter('id', $id, IQueryBuilder::PARAM_INT);
@ -35,7 +35,7 @@ class RecipeDb {
public function deleteRecipeById(int $id) {
$qb = $this->db->getQueryBuilder();
$qb->delete('cookbook_recipes')
$qb->delete('cookbook_names')
->where('recipe_id = :id');
$qb->setParameter('id', $id, IQueryBuilder::PARAM_INT);
@ -52,7 +52,7 @@ class RecipeDb {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('cookbook_recipes', 'r')
->from('cookbook_names', 'r')
->where('user_id = :user')
->orderBy('r.name');
$qb->setParameter('user', $userId, TYPE::STRING);
@ -77,7 +77,7 @@ class RecipeDb {
$result = $cursor->fetchAll();
$cursor->closeCursor();
$result = array_unique($result);
$result = array_unique($result, SORT_REGULAR);
return $result;
}
@ -117,7 +117,7 @@ class RecipeDb {
$qb->setParameters($params, $types);
$qb->setParameter('user', $userId, TYPE::STRING);
$qb->join('k', 'cookbook_recipes', 'r', 'k.recipe_id = r.recipe_id');
$qb->join('k', 'cookbook_names', 'r', 'k.recipe_id = r.recipe_id');
$qb->groupBy('r.recipe_id');
$qb->orderBy('r.name');
@ -132,7 +132,7 @@ class RecipeDb {
public function emptySearchIndex(string $userId) {
$qb = $this->db->getQueryBuilder();
$qb->delete('cookbook_recipes')
$qb->delete('cookbook_names')
->where('user_id = :user')
->orWhere('user_id = :empty');
$qb->setParameter('user', $userId, TYPE::STRING);
@ -161,7 +161,7 @@ class RecipeDb {
$qb = $this->db->getQueryBuilder();
// Insert recipe
$qb->delete('cookbook_recipes')
$qb->delete('cookbook_names')
->where('recipe_id = :id')
->andWhere('user_id = :user');
$qb->setParameter('id', $id, IQueryBuilder::PARAM_INT);
@ -169,7 +169,7 @@ class RecipeDb {
$qb->execute();
$qb->insert('cookbook_recipes')
$qb->insert('cookbook_names')
->values([
'recipe_id' => ':id',
'name' => ':name',

Просмотреть файл

@ -0,0 +1,44 @@
<?php
namespace OCA\Cookbook\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
use Doctrine\DBAL\Schema\Constraint;
use Doctrine\DBAL\Types\Type;
class Version000000Date20190910223344 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
// Because of Postgres, we have to drop this table entirely in order to remove the primary key and allow multi user tables
$schema->dropTable('cookbook_recipes');
// Also because of Postgres, we have to start using another name, because we can't recreate the table with the same name in the same migration method
$table = $schema->createTable('cookbook_names');
$table->addColumn('recipe_id', 'integer', [
'notnull' => true,
]);
$table->addColumn('name', 'string', [
'notnull' => true,
'length' => 128,
]);
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
]);
return $schema;
}
}
?>