Bug 5430: Follow-up, fixes error message when no 001 exists
[koha.git] / C4 / Creators / Template.pm
index e43a3cd..8a7564c 100644 (file)
@@ -89,7 +89,7 @@ sub new {
     my $invocant = shift;
     my $type = ref($invocant) || $invocant;
     if (_check_params(@_) eq 1) {
-        return;
+        return -1;
     }
     my $self = {
         profile_id      =>      0,
@@ -124,7 +124,7 @@ sub retrieve {
     $sth->execute($opts{'template_id'}, $opts{'creator'});
     if ($sth->err) {
         warn sprintf('Database returned the following error: %s', $sth->errstr);
-        return;
+        return -1;
     }
     my $self = $sth->fetchrow_hashref;
     $self = _conv_points($self) if (($opts{convert} && $opts{convert} == 1) || $opts{profile_id});
@@ -152,9 +152,9 @@ sub delete {
     if (scalar(@query_params) < 2) {   # If there is no template id or creator type then we cannot delete it
         warn sprintf('%s : Cannot delete template as the template id is invalid or non-existant.', $call_type) if !$query_params[0];
         warn sprintf('%s : Cannot delete template as the creator type is invalid or non-existant.', $call_type) if !$query_params[1];
-        return;
+        return -1;
     }
-    my $query = "DELETE FROM " . $opts{'table_name'} . " WHERE template_id = ? AND creator = ?";
+    my $query = "DELETE FROM creator_templates WHERE template_id = ? AND creator = ?";
     my $sth = C4::Context->dbh->prepare($query);
     $sth->execute(@query_params);
     $self->{'template_stat'} = 0;
@@ -178,7 +178,7 @@ sub save {
         $sth->execute(@params);
         if ($sth->err) {
             warn sprintf('Database returned the following error: %s', $sth->errstr);
-            return;
+            return -1;
         }
         $self->{'template_stat'} = 1;
         return $self->{'template_id'};
@@ -202,7 +202,7 @@ sub save {
         $sth->execute(@params);
         if ($sth->err) {
             warn sprintf('Database returned the following error: %s', $sth->errstr);
-            return;
+            return -1;
         }
         my $sth1 = C4::Context->dbh->prepare("SELECT MAX(template_id) FROM " . $opts{'table_name'} . ";");
         $sth1->execute();
@@ -216,19 +216,21 @@ sub save {
 sub get_attr {
     my $self = shift;
     if (_check_params(@_) eq 1) {
-        return;
+        return -1;
     }
     my ($attr) = @_;
     if (exists($self->{$attr})) {
         return $self->{$attr};
     }
-    return;
+    else {
+        return -1;
+    }
 }
 
 sub set_attr {
     my $self = shift;
     if (_check_params(@_) eq 1) {
-        return;
+        return -1;
     }
     my %attrs = @_;
     foreach my $attrib (keys(%attrs)) {
@@ -372,7 +374,7 @@ CM      = SI Centimeters (28.3464567 points per)
 =head2 save()
 
     Invoking the I<save> method attempts to insert the template into the database if the template is new and update the existing template record if
-    the template exists. The method returns the new record template_id upon success and undef upon failure (This avoids template_ids conflicting with a
+    the template exists. The method returns the new record template_id upon success and -1 upon failure (This avoids template_ids conflicting with a
     record template_id of 1). Errors are logged to the Apache log.
 
     example:
@@ -380,7 +382,7 @@ CM      = SI Centimeters (28.3464567 points per)
 
 =head2 get_attr($attribute)
 
-    Invoking the I<get_attr> method will return the value of the requested attribute or undef on errors.
+    Invoking the I<get_attr> method will return the value of the requested attribute or -1 on errors.
 
     example:
         C<my $value = $template->get_attr($attribute);>