# Copyright (c) 2006-2009 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: BlogCreateForm.pm,v 1.6 2009/05/25 02:03:54 nagler Exp $ package Bivio::Biz::Model::BlogCreateForm; use strict; use Bivio::Base 'Model.WikiBaseForm'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.6 $ =~ /\d+/g); my($_BFN) = b_use('Type.BlogFileName'); my($_BC) = b_use('Type.BlogContent'); my($_DT) = b_use('Type.DateTime'); sub execute_ok { my($self) = @_; my($now) = $_DT->now; my($rf) = $self->new_other('RealmFile'); my($bfn); my($p) = $self->unsafe_get('RealmFile.is_public') ? 1 : 0; foreach my $x (1..100) { $bfn = $_BFN->from_date_time($now); my($v) = { path => $_BFN->to_absolute($bfn, $p), is_public => $p, }; unless ($rf->unsafe_load($v)) { $rf->create_with_content( $v, $_BC->join($self->get(qw(title body)))); $self->get_request->put(); return $self->return_with_validate({ path_info => $bfn, }); } $bfn = undef; $now = $_DT->add_seconds($now, 1); } $self->die( $_BFN->from_date_time($now) , ': unable to create unique file', ); # DOES NOT RETURN } sub internal_initialize { my($self) = @_; return $self->merge_initialize_info($self->SUPER::internal_initialize, { version => 1, visible => [ { name => 'title', type => 'BlogTitle', constraint => 'NOT_NULL', }, { name => 'body', type => 'BlogBody', constraint => 'NOT_NULL', }, { name => 'RealmFile.is_public', constraint => 'NONE', }, ], }); } 1;