/* first, it is a new version - and version may change pathname, updating file_version increases version */
/* TODO: version control!!!! */
// @co_call(par_area,par_class,'increaseVersion',par_id=>par_id,par_area=>par_area,par_class=>par_class);
@co_call(par_area,par_class,'getProp',par_id=>par_id,par_area=>par_area,par_class=>par_class, prop_name=>'"file_version"');
__GET_RETURNED_STRING(str_file_version)
file_version = atoi(str_file_version);
str_file_version = ap_psprintf(p, "%d", file_version+1);
@co_call(par_area,par_class,'update',par_id=>par_id,par_area=>par_area,par_class=>par_class, version=>-1, par_prop=>'"file_version"', new_value=>str_file_version);
@co_call(par_area,par_class,'getPath',par_id=>par_id,par_area=>par_area,par_class=>par_class);
partial_path = cou_getReturnValue( cnx, CO_STRING, &err );
pathname = ap_psprintf( p, "%s/%s", cou_getCODataPath() , partial_path );
fd = ap_popenf(p, pathname, O_WRONLY | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);
if (fd == -1)
{
__SEND_MESG_DEBUG("couldn't open file %s for writing",pathname)
/* abort transaction - back to the old version */
cou_error(cnx, "couldn't open file for writing!");
}
len = strlen(text);
if (write(fd, text, len) != len) {
__SEND_MESG_DEBUG("couldn't write to file %s", pathname)
ap_pclosef(p, fd);
/* abort transaction - back to the old version */
cou_error(cnx, "couldn't save file!");
}
if (ap_pclosef(p, fd) == -1) cou_logError(cnx, CO_LOG_DEBUG, "couldn't close file %s", pathname);
/* should we continue if we can't close? */
__SEND_MESG_DEBUG("writeFileFromString")
// for html compatibility
if(cnx->client_mode==CO_CLIENT_HTML)
{
ap_rprintf(r, "Text changed");
}