Fix errors in recipe editing code

This commit is contained in:
Chris 2019-01-27 16:40:51 +00:00
parent 7f75f6deea
commit e8dbbfc354
5 changed files with 23 additions and 16 deletions

View File

@ -11,9 +11,9 @@ RewriteEngine On
# If the installation is in a subdirectory, add a rewritebase rule for the subdir
# RewriteBase /subdir/
RewriteBase /orb/
#RewriteBase /
RewriteCond %{REQUEST_URI} !^/orb/(templates|media|docs|ckeditor|images|data|index.cgi)
RewriteCond %{REQUEST_URI} !^/(templates|media|docs|ckeditor|images|data|index.cgi)
RewriteRule (.*) index.cgi/$1 [PT,L]
# Compress text, html, javascript, css, xml:

View File

@ -92,7 +92,7 @@ sub _generate_edit {
$args -> {"tags"} = $self -> _convert_tags($args -> {"tags"});
$self -> _convert_ingredients($args);
# User must have recipe create to proceed.
# User must have recipe edit to proceed.
return $self -> _fatal_error("{L_PERMISSION_FAILED_SUMMARY}")
unless($self -> check_permission('recipe.edit', $args -> {"metadata_id"}));
@ -112,7 +112,7 @@ sub _generate_edit {
or $errors = $self -> {"template"} -> load_template("error/error_item.tem",
{ "%(error)s" => $self -> {"system"} -> {"recipe"} -> errstr() });
# Did the addition work? If so, send the user to the view page for the new recipe
# Did the edit work? If so, send the user to the view page for the new recipe
return $self -> redirect($self -> build_url(block => "view",
pathinfo => [ $args -> {"id"} ],
params => "",

5
lang/en/delete.lang Normal file
View File

@ -0,0 +1,5 @@
DELETE_FAILED_BADID = Unable to delete recipe: the specified recipe identifier is invalid.
DELETE_FAILED_NOTFOUND = Unable to locate a recipe with the specified identifier.
DELETE_ERROR_FATAL = Deletion error
DELETE_FAILED = Unable to delete recipe

View File

@ -80,7 +80,8 @@ sub init {
settings => $self -> {"settings"},
logger => $self -> {"logger"},
metadata => $self -> {"metadata"},
entities => $self -> {"entities"})
entities => $self -> {"entities"},
roles => $self -> {"roles"})
or return $self -> self_error("Recipe model init failed: ".$Webperl::SystemModule::errstr);
return 1;

View File

@ -29,7 +29,7 @@ use v5.14;
use experimental qw(smartmatch);
use Webperl::Utils qw(hash_or_hashref array_or_arrayref);
use Data::Dumper;
# ============================================================================
# Constructor and cleanup
@ -140,8 +140,8 @@ sub create {
# Do the insert, and fetch the ID of the new row
my $newh = $self -> {"dbh"} -> prepare("INSERT INTO `".$self -> {"settings"} -> {"database"} -> {"recipes"}."`
(`id`, `metadata_id`, `original_id`, `name`, `source`, `prepinfo`, `preptime`, `cooktime`, `yield`, `temp`, `temptype`, `method`, `notes`, `type_id`, `status_id`, `creator_id`, `created`, `updater_id`, `updated`)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,?)");
(`id`, `metadata_id`, `original_id`, `name`, `source`, `prepinfo`, `preptime`, `cooktime`, `yield`, `temp`, `temptype`, `method`, `notes`, `type_id`, `status_id`, `creator_id`, `created`, `updater_id`, `updated`, `viewed`)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
my $result = $newh -> execute($args -> {"id"},
$args -> {"metadataid"},
$args -> {"origid"},
@ -160,7 +160,8 @@ sub create {
$args -> {"creatorid"},
$args -> {"created"},
$args -> {"creatorid"},
$args -> {"created"});
$args -> {"created"},
0);
return $self -> self_error("Insert of recipe failed: ".$self -> {"dbh"} -> errstr)
if(!$result);
@ -178,11 +179,11 @@ sub create {
or return $self -> self_error("Error in metadata system: ".$self -> {"metadata"} -> errstr());
# Add the user as an editor
my $roleid = $self -> {"system"} -> {"roles"} -> role_get_roleid("editor");
$self -> {"system"} -> {"roles"} -> user_assign_role($args -> {"metadataid"},
my $roleid = $self -> {"roles"} -> role_get_roleid("editor");
$self -> {"roles"} -> user_assign_role($args -> {"metadataid"},
$args -> {"creatorid"},
$roleid)
or return $self -> self_error($self -> {"system"} -> {"roles"} -> {"errstr"});
or return $self -> self_error($self -> {"roles"} -> {"errstr"});
# Add the ingredients for the recipe
$self -> _add_ingredients($newid, $args -> {"ingredients"})
@ -861,8 +862,8 @@ sub _renumber_recipe {
# Duplicate the source recipe at the end of the table
my $moveh = $self -> {"dbh"} -> prepare("INSERT INTO `".$self -> {"settings"} -> {"database"} -> {"recipes"}."`
(`metadata_id`, `name`, `method`, `notes`, `source`, `yield`, `prepinfo`, `preptime`, `cooktime`, `temptype`, `temp`, `type_id`, `status_id`, `creator_id`, `created`, `viewed`)
SELECT `metadata_id`, `name`, `method`, `notes`, `source`, `yield`, `prepinfo`, `preptime`, `cooktime`, `temptype`, `temp`, `type_id`, `status_id`, `creator_id`, `created`, `viewed`
(`metadata_id`, `name`, `method`, `notes`, `source`, `yield`, `prepinfo`, `preptime`, `cooktime`, `temptype`, `temp`, `type_id`, `status_id`, `creator_id`, `created`, `updater_id`, `updated`, `viewed`)
SELECT `metadata_id`, `name`, `method`, `notes`, `source`, `yield`, `prepinfo`, `preptime`, `cooktime`, `temptype`, `temp`, `type_id`, `status_id`, `creator_id`, `created`, `updater_id`, `updated`, `viewed`
FROM `".$self -> {"settings"} -> {"database"} -> {"recipes"}."`
WHERE `id` = ?");
my $rows = $moveh -> execute($sourceid);