<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[GlotPress][904] trunk/gp-includes/routes: Return all die_with_404() and die_with_error() calls in GP_Route_Project.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://glotpress.trac.wordpress.org/changeset/904">904</a></dd>
<dt>Author</dt> <dd>markoheijnen</dd>
<dt>Date</dt> <dd>2014-05-09 18:41:57 +0000 (Fri, 09 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Return all die_with_404() and die_with_error() calls in GP_Route_Project. See <a href="http://glotpress.trac.wordpress.org/ticket/321">#321</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkgpincludesroutesglossaryentryphp">trunk/gp-includes/routes/glossary-entry.php</a></li>
<li><a href="#trunkgpincludesroutesprojectphp">trunk/gp-includes/routes/project.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkgpincludesroutesglossaryentryphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/routes/glossary-entry.php (903 => 904)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/routes/glossary-entry.php      2014-05-09 18:22:48 UTC (rev 903)
+++ trunk/gp-includes/routes/glossary-entry.php 2014-05-09 18:41:57 UTC (rev 904)
</span><span class="lines">@@ -66,7 +66,7 @@
</span><span class="cx">          $can_edit        = $this->can( 'approve', 'translation-set', $translation_set->id );
</span><span class="cx"> 
</span><span class="cx">          if ( ! $can_edit ) {
</span><del>-                       $this->die_with_error( __('Forbidden'), 403 );
</del><ins>+                        return $this->die_with_error( __('Forbidden'), 403 );
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          $project = GP::$project->get( $translation_set->project_id );
</span></span></pre></div>
<a id="trunkgpincludesroutesprojectphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/routes/project.php (903 => 904)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/routes/project.php     2014-05-09 18:22:48 UTC (rev 903)
+++ trunk/gp-includes/routes/project.php        2014-05-09 18:41:57 UTC (rev 904)
</span><span class="lines">@@ -9,9 +9,14 @@
</span><span class="cx"> 
</span><span class="cx">  function single( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
</ins><span class="cx">           $sub_projects = $project->sub_projects();
</span><span class="cx">          $translation_sets = GP::$translation_set->by_project_id( $project->id );
</span><ins>+
</ins><span class="cx">           foreach( $translation_sets as $set ) {
</span><span class="cx">                  $set->name_with_locale = $set->name_with_locale();
</span><span class="cx">                  $set->current_count = $set->current_count();
</span><span class="lines">@@ -32,8 +37,15 @@
</span><span class="cx"> 
</span><span class="cx">  function personal_options_post( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $user = GP::$user->current();
</span><span class="cx">          $source_url_templates = $user->get_meta( 'source_url_templates' );
</span><span class="cx">          if ( !is_array( $source_url_templates ) ) $source_url_templates = array();
</span><span class="lines">@@ -47,33 +59,49 @@
</span><span class="cx"> 
</span><span class="cx">  function import_originals_get( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $kind = 'originals';
</span><span class="cx">          $this->tmpl( 'project-import', get_defined_vars() );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  function import_originals_post( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><span class="cx"> 
</span><ins>+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $format = gp_array_get( GP::$formats, gp_post( 'format', 'po' ), null );
</span><del>-               if ( !$format ) {
</del><ins>+
+               if ( ! $format ) {
</ins><span class="cx">                   $this->redirect_with_error( __('No such format.') );
</span><span class="cx">                  return;
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-               if ( !is_uploaded_file( $_FILES['import-file']['tmp_name'] ) ) {
</del><ins>+                if ( ! is_uploaded_file( $_FILES['import-file']['tmp_name'] ) ) {
</ins><span class="cx">                   // TODO: different errors for different upload conditions
</span><span class="cx">                  $this->redirect_with_error( __('Error uploading the file.') );
</span><span class="cx">                  return;
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          $translations = $format->read_originals_from_file( $_FILES['import-file']['tmp_name'] );
</span><del>-               if ( !$translations ) {
</del><ins>+
+               if ( ! $translations ) {
</ins><span class="cx">                   $this->redirect_with_error( __('Couldn&#8217;t load translations from file!') );
</span><ins>+                       return;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          list( $originals_added, $originals_existing ) = GP::$original->import_for_project( $project, $translations );
</span><span class="lines">@@ -84,24 +112,45 @@
</span><span class="cx"> 
</span><span class="cx">  function edit_get( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $this->tmpl( 'project-edit', get_defined_vars() );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  function edit_post( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( !$project ) {
+                       $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $updated_project = new GP_Project( gp_post( 'project' ) );
</span><del>-               if ( $this->invalid_and_redirect( $updated_project, gp_url_project( $project, '-edit' ) ) ) return;
</del><ins>+                if ( $this->invalid_and_redirect( $updated_project, gp_url_project( $project, '-edit' ) ) ) {
+                       return;
+               }
+
</ins><span class="cx">           // TODO: add id check as a validation rule
</span><del>-               if ( $project->id == $updated_project->parent_project_id )
</del><ins>+                if ( $project->id == $updated_project->parent_project_id ) {
</ins><span class="cx">                   $this->errors[] = __('The project cannot be parent of itself!');
</span><del>-               elseif ( $project->save( $updated_project ) )
</del><ins>+                }
+               elseif ( $project->save( $updated_project ) ) {
</ins><span class="cx">                   $this->notices[] = __('The project was saved.');
</span><del>-               else
</del><ins>+                }
+               else {
</ins><span class="cx">                   $this->errors[] = __('Error in saving project!');
</span><ins>+               }
+
</ins><span class="cx">           $project->reload();
</span><span class="cx"> 
</span><span class="cx">          $this->redirect( gp_url_project( $project ) );
</span><span class="lines">@@ -112,12 +161,22 @@
</span><span class="cx">          // TODO: decide what to do with child projects and translation sets
</span><span class="cx">          // TODO: just deactivate, do not actually delete
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
-               if ( $project->delete() )
</del><ins>+
+               if ( !$project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
+               if ( $project->delete() ) {
</ins><span class="cx">                   $this->notices[] = __('The project was deleted.');
</span><del>-               else
</del><ins>+                }
+               else {
</ins><span class="cx">                   $this->errors[] = __('Error in deleting project!');
</span><ins>+               }
+
</ins><span class="cx">           $this->redirect( gp_url_project( '' ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -125,18 +184,31 @@
</span><span class="cx">  function new_get() {
</span><span class="cx">          $project = new GP_Project();
</span><span class="cx">          $project->parent_project_id = gp_get( 'parent_project_id', null );
</span><del>-               if ( $this->cannot_and_redirect( 'write', 'project', $project->parent_project_id ) ) return;
</del><ins>+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->parent_project_id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $this->tmpl( 'project-new', get_defined_vars() );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  function new_post() {
</span><span class="cx">          $post = gp_post( 'project' );
</span><span class="cx">          $parent_project_id = gp_array_get( $post, 'parent_project_id', null );
</span><del>-               if ( $this->cannot_and_redirect( 'write', 'project', $parent_project_id ) ) return;
</del><ins>+
+               if ( $this->cannot_and_redirect( 'write', 'project', $parent_project_id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $new_project = new GP_Project( $post );
</span><del>-               if ( $this->invalid_and_redirect( $new_project ) ) return;
</del><ins>+
+               if ( $this->invalid_and_redirect( $new_project ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $project = GP::$project->create_and_select( $new_project );
</span><del>-               if ( !$project ) {
</del><ins>+
+               if ( ! $project ) {
</ins><span class="cx">                   $project = new GP_Project();
</span><span class="cx">                  $this->errors[] = __('Error in creating project!');
</span><span class="cx">                  $this->tmpl( 'project-new', get_defined_vars() );
</span><span class="lines">@@ -148,13 +220,21 @@
</span><span class="cx"> 
</span><span class="cx">  function permissions_get( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $path_to_root = array_slice( $project->path_to_root(), 1 );
</span><span class="cx">          $permissions = GP::$validator_permission->by_project_id( $project->id );
</span><span class="cx">          $cmp_fn = lambda( '$x, $y', 'strcmp($x->locale_slug, $y->locale_slug);' );
</span><span class="cx">          usort( $permissions, $cmp_fn );
</span><span class="cx">          $parent_permissions = array();
</span><ins>+
</ins><span class="cx">           foreach( $path_to_root as $parent_project ) {
</span><span class="cx">                  $this_parent_permissions = GP::$validator_permission->by_project_id( $parent_project->id );
</span><span class="cx">                  usort( $this_parent_permissions, $cmp_fn );
</span><span class="lines">@@ -172,8 +252,15 @@
</span><span class="cx"> 
</span><span class="cx">  function permissions_post( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           if ( 'add-validator' == gp_post( 'action' ) ) {
</span><span class="cx">                  $user = GP::$user->by_login( gp_post( 'user_login' ) );
</span><span class="cx">                  if ( !$user ) {
</span><span class="lines">@@ -197,8 +284,15 @@
</span><span class="cx"> 
</span><span class="cx">  function permissions_delete( $project_path, $permission_id ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $permission = GP::$permission->get( $permission_id );
</span><span class="cx">          if ( $permission ) {
</span><span class="cx">                  if ( $permission->delete() ) {
</span><span class="lines">@@ -214,19 +308,34 @@
</span><span class="cx"> 
</span><span class="cx">  function mass_create_sets_get( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $this->tmpl( 'project-mass-create-sets', get_defined_vars() );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  function mass_create_sets_post( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+                if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $other_project = GP::$project->get( gp_post( 'project_id' ) );
</span><del>-               if ( !$other_project ) {
-                       $this->die_with_error( __('Project wasn&#8217;found') );
</del><ins>+
+               if ( ! $other_project ) {
+                       return $this->die_with_error( __('Project wasn&#8217;found') );
</ins><span class="cx">           }
</span><ins>+
</ins><span class="cx">           $changes = $project->set_difference_from( $other_project );
</span><span class="cx">          $errors = 0;
</span><span class="cx">          foreach( $changes['added'] as $to_add ) {
</span><span class="lines">@@ -245,21 +354,32 @@
</span><span class="cx"> 
</span><span class="cx">  function mass_create_sets_preview_post( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) $this->die_with_404();
-               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) return;
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
+               }
+
+               if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
+                       return;
+               }
+
</ins><span class="cx">           $other_project = GP::$project->get( gp_post( 'project_id' ) );
</span><del>-               if ( !$other_project ) {
-                       $this->die_with_error( __('Project wasn&#8217;found') );
</del><ins>+
+               if ( ! $other_project ) {
+                       return $this->die_with_error( __('Project wasn&#8217;found') );
</ins><span class="cx">           }
</span><ins>+
</ins><span class="cx">           header('Content-Type: application/json');
</span><span class="cx">          echo json_encode( $project->set_difference_from( $other_project ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  function branch_project_get( $project_path ) {
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) {
-                       $this->die_with_404();
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
</ins><span class="cx">           }
</span><ins>+
</ins><span class="cx">           if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ) {
</span><span class="cx">                  return;
</span><span class="cx">          }
</span><span class="lines">@@ -271,8 +391,9 @@
</span><span class="cx">  function branch_project_post( $project_path ) {
</span><span class="cx">          $post = gp_post( 'project' );
</span><span class="cx">          $project = GP::$project->by_path( $project_path );
</span><del>-               if ( !$project ) {
-                       $this->die_with_404();
</del><ins>+
+               if ( ! $project ) {
+                       return $this->die_with_404();
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          $parent_project_id = gp_array_get( $post, 'parent_project_id', null );
</span><span class="lines">@@ -299,4 +420,5 @@
</span><span class="cx"> 
</span><span class="cx">          $this->redirect( gp_url_project( $new_project ) );
</span><span class="cx">  }
</span><ins>+
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>