Example #1
0
 public static function edit_recipe_head($recipe_id, $recipe_version_id)
 {
     ////
     // Turn MySQL commiting off, run as a transaction
     ////
     MySQLConnection::autocommit(false);
     $SQL = "UPDATE recipes\n\t\t\t           SET modified = UTC_TIMESTAMP()\n\t\t\t         WHERE `id` = " . MySQLConnection::smart_quote($recipe_id) . "";
     MySQLConnection::query($SQL) or Error::db_halt(500, 'internal server error', 'Unable to execute request, SQL query error.', __FUNCTION__, MySQLConnection::error(), $SQL);
     $SQL = "UPDATE recipe_heads\n\t\t\t           SET recipe_version = " . MySQLConnection::smart_quote($recipe_version_id) . "\n\t\t\t         WHERE recipe = " . MySQLConnection::smart_quote($recipe_id) . "";
     MySQLConnection::query($SQL) or Error::db_halt(500, 'internal server error', 'Unable to execute request, SQL query error.', __FUNCTION__, MySQLConnection::error(), $SQL);
     ////
     // Commit the MySQL transaction
     ////
     MySQLConnection::commit();
 }
Example #2
0
 public static function edit_recipe($recipe_id, $recipe_name, $recipe_interpreter, $recipe_notes, $recipe_content)
 {
     $SQL = "UPDATE recipes\n\t\t\t           SET name = " . MySQLConnection::smart_quote($recipe_name) . ",\n\t\t\t               modified = UTC_TIMESTAMP()\n\t\t\t         WHERE `id` = " . MySQLConnection::smart_quote($recipe_id) . "";
     MySQLConnection::query($SQL) or Error::db_halt(500, 'internal server error', 'Unable to execute request, SQL query error.', __FUNCTION__, MySQLConnection::error(), $SQL);
     ////
     // Generate SHA1
     ////
     $sha1 = sha1($recipe_id . $recipe_interpreter . $recipe_notes . $recipe_content);
     ////
     // Get if head version matches generated sha1 above
     ////
     $SQL = "SELECT rv.version\n\t\t\t          FROM recipe_heads rh,\n\t\t\t               recipe_versions rv\n\t\t\t         WHERE rh.recipe = rv.recipe\n\t\t\t           AND rh.recipe_version = rv.id \n\t\t\t           AND rh.recipe = " . MySQLConnection::smart_quote($recipe_id) . "\n\t\t\t           AND rv.version = " . MySQLConnection::smart_quote($sha1) . "";
     $result = MySQLConnection::query($SQL) or Error::db_halt(500, 'internal server error', 'Unable to execute request, SQL query error.', __FUNCTION__, MySQLConnection::error(), $SQL);
     $numb_rows = MySQLConnection::numb_rows($result);
     ////
     // This update is the same as head, don't store another version, simply return
     ////
     if ($numb_rows > 0) {
         return;
     }
     ////
     // Turn MySQL commiting off, run as a transaction
     ////
     MySQLConnection::autocommit(false);
     $recipe_version_id = Functions::generate_id('ver');
     $SQL = "INSERT INTO recipe_versions\n\t\t\t                   (`id`,\n\t\t\t                    recipe,\n\t\t\t                    version,\n\t\t\t                    interpreter,\n\t\t\t                    notes,\n\t\t\t                    content,\n\t\t\t                    added)\n\t\t\t            VALUES (" . MySQLConnection::smart_quote($recipe_version_id) . ",\n\t\t\t            \t\t" . MySQLConnection::smart_quote($recipe_id) . ", \n\t\t\t            \t\tSHA1(" . MySQLConnection::smart_quote($recipe_id . $recipe_interpreter . $recipe_notes . $recipe_content) . "),\n\t\t\t            \t\t" . MySQLConnection::smart_quote($recipe_interpreter) . ",\n\t\t\t            \t\t" . MySQLConnection::smart_quote($recipe_notes) . ",\n\t\t\t            \t\t" . MySQLConnection::smart_quote($recipe_content) . ",\n\t\t\t            \t\tUTC_TIMESTAMP())";
     MySQLConnection::query($SQL) or Error::db_halt(500, 'internal server error', 'Unable to execute request, SQL query error.', __FUNCTION__, MySQLConnection::error(), $SQL);
     $SQL = "UPDATE recipe_heads\n\t\t\t           SET recipe_version = " . MySQLConnection::smart_quote($recipe_version_id) . "\n\t\t\t         WHERE recipe = " . MySQLConnection::smart_quote($recipe_id) . "";
     MySQLConnection::query($SQL) or Error::db_halt(500, 'internal server error', 'Unable to execute request, SQL query error.', __FUNCTION__, MySQLConnection::error(), $SQL);
     ////
     // Commit the MySQL transaction
     ////
     MySQLConnection::commit();
 }