Deleting Composers (continued)

Submitting SQL Delete command

Now that the right composer has been selected for deletion we have to construct a suitable SQL command and submit it. The flow variable composerId was taken from the hidden form field.

<page:content> <t:heading level="1">SQL Delete Composer</t:heading> <execute-query xmlns=""> <query name="runDeleteComposer" database="composers">DELETE FROM composer WHERE id='{flow:composerId}'</query> </execute-query> <t:p><link:link type="uri" ref="examples/sql/sql.html">Return to SQL index</link:link></t:p> <t:p><link:link type="uri" ref="examples/sql/logout.html">Logout</link:link> from admin pages.</t:p> </page:content>

Extending the Flow Script

The flow script is modified:

function delete() { global $gModules; $this->gLogger->debug( "Delete composer, continuation: " . $this->gContinuation ); $this->gViolations = array(); $finished = false; while ( !$finished ) { $this->gLogger->debug( "Processing: " . $this->gContinuation ); $errors = false; switch ( $this->gContinuation ) { case 0 : $this->sendPage( "deleteComposer-1.html", // The page to send to the client $this->gDeleteComposerModel, // The current data model to send ++$this->gContinuation, // The continuation link for the next stage $this->gViolations ); // Array of errors (keyed by data model keys) $finished = true; break; case 1 : // Error processing here. Only have to check whether a composer has been selected. $this->gLogger->debug( "Checking: '" . $this->gDeleteComposerModel[ 'selectDeleteComposer' ] . "'" ); if ( strlen( $this->gDeleteComposerModel[ 'selectDeleteComposer' ] ) == 0 ) { $this->gViolations[ 'selectDeleteComposer' ] = "Need a composer to delete"; $errors = true; } if ( $errors ) { $this->gContinuation--; $finished = false; } else { $this->sendPage( "deleteComposer-2.html", $this->gDeleteComposerModel, ++$this->gContinuation, $this->gViolations ); $finished = true; } break; case 2 : $this->sendPage( "deleteComposer-3.html", $this->gDeleteComposerModel, ++$this->gContinuation, $this->gViolations ); $finished = true; break; } // switch } // while } // function delete()

Extending the Sitemap

And the sitemap modified:

<map:pipeline internal-only="true"> <map:match pattern="deleteComposer-3.html"> <map:aggregate element="root" label="aggr-content"> <map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/> <map:part src="cocoon:/deleteComposer-3.px" element="content" strip-root="true"/> </map:aggregate> <map:transform type="mysql" label="sql-content"/> <map:transform src="context://resources/transforms/sql2xml.xsl" label="sql-transform"/> <map:call resource="outputPage"/> </map:match> <map:match pattern="deleteComposer-*.html"> <map:act type="auth-protect"> <map:parameter name="handler" value="adminHandler"/> <map:aggregate element="root" label="aggr-content"> <map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/> <map:part src="cocoon:/deleteComposer-{1}.px" element="content" strip-root="true"/> </map:aggregate> <map:transform type="mysql" label="sql-content"> <map:parameter name="show-nr-of-rows" value="true"/> </map:transform> <map:transform src="context://resources/transforms/sql2pform.xsl"/> <map:transform src="resource://resources/transforms/pforms-violations.xsl" label="pforms-violations"> <map:parameter name="formViolations" value="{session:__violations}"/> </map:transform> <map:transform src="resource://resources/transforms/pforms-default.xsl" label="pforms-default"/> <map:transform src="resource://resources/transforms/pforms2html.xsl" label="pforms-html"/> <map:call resource="outputPage"/> </map:act> </map:match> </map:pipeline>

The matcher is simpler as we do not have to process any PForms. The result of a successful deletion is:

The next section looks at protecting some of the pages..

Copyright 2006 — 2010 Hugh Field-Richards. All Rights Reserved.