Important announcements from CouchCMS team
63 posts Page 6 of 7
Previous 1 ... 3, 4, 5, 6, 7 Next
That worked perfectly. Thanks for the help.
I'm dealing with a situation in which the CSV file is an export from an Excel sheet, used to keep track of an organisations small library of books. The potential problem is that the Excel sheet is also used directly, and it has some column headers with spaces in them (for example, 'Number of Copies').

The problem is that the CSV importer tries to write these into Couch variables with a space in the name, and trying to use variables with an embedded space doesn't go well!

To deal with this, I've added a line to the CSV importer as below (the line is commented; the others are for context). This simply replaces the spaces with underscores; if your data source uses underscores *and* spaces this may get confusing, but I guess that's fairly uncommon!

Code: Select all
                    foreach( $rec as $k=>$v ){
                        $k = str_replace(" ","_",$k); //replace spaces with underscores in column headers
                        $CTX->set( $prefix.$k, $v );
                    } 


This is at lines 356-358 of the file in the download linked on the first post of this topic, but looking at the Github repo it's at lines 363-366 in the latest version. I probably need to upgrade!

@KK - feel free to incorporate / criticise!
@daldred, there was a recent discussion on this very topic -
viewtopic.php?f=4&t=13080&p=37361#p37361

As you'll find in the solution suggested by me there, spaces in variable names can be handled without much difficulty and so, IMHO, there should be no need to modify the addon's code.

Would like to get your thoughts.
KK wrote: @daldred, there was a recent discussion on this very topic -
viewtopic.php?f=4&t=13080&p=37361#p37361

As you'll find in the solution suggested by me there, spaces in variable names can be handled without much difficulty and so, IMHO, there should be no need to modify the addon's code.

Would like to get your thoughts.


I don't know how I managed to miss that one when looking in the forums...

I think there are advantages either way; but that way is probably better given that it doesn't introduce an arbitrary (albeit common) character substitution.

Would it be possible to edit the original post on this thread to refer to that way of getting the values? I often find that finding things like this in the forum can be tricky - and if as much as possible is concentrated into the thread that introduces the enhancement it helps to find it later!
That's an awesome solution!

I've tested with a clonable page that I have here, and It works like a charm!

However, there is something i've been thinking about: Could this be used with pages which has a mosaic? How?
I've just had to reinstall XAMPP on my local machine (long story!). In doing so I've moved it up to PHP8, which may be relevant to this. (I'm seeing quite a lot of deprecations and warnings from PHP - to the extent that I've turned them off for the moment).

One of my sites uses the CSV importer. If I try to start that site now on localhost, it says:
Code: Select all
ERROR function register_tag(): handler function of Tag "csv_reader" not callable


(This is a Couch error report, rather than a PHP one).

If I remove the 'require-once' line relating to the csv importer from couch/.addons/kfunctions.php, the error goes away - everything else seems to work.
@daldred
I'm seeing quite a lot of deprecations and warnings from PHP
I suppose you are not using the latest version of Couch, are you?
Please upgrade to it and let us know if you still hit those warnings.

ERROR function register_tag(): handler function of Tag "csv_reader" not callable
Once again, please use the latest version of this addon that is available from GitHub.
Let us know if the error persists.

Thanks.
Thanks, @KK - the upgrade sorted this out. I'd quite forgotten how old that specific site was!
Hi guys!

Im having a issue with this module I would be really grateful for your help.

I tried to test with the example but it didn't work and no new records are actually added to the db (checked via phpyadmin)

I'll explain you what I did

I installed a plugin by copying csv folder to the couch/addons

I renamed kfunctions example file to kfunctions.php

Inside it looks like this:

Code: Select all
<?php
if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly

require_once( K_COUCH_DIR.'addons/csv/csv.php' );
//require_once( K_COUCH_DIR.'addons/cart/session.php' );
//require_once( K_COUCH_DIR.'addons/cart/cart.php' ); // automatically includes session
require_once( K_COUCH_DIR.'addons/data-bound-form/data-bound-form.php' );
//require_once( K_COUCH_DIR.'addons/inline/inline.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-folders.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-comments.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-users.php' );


I copied cars.php file that was included in the install file. I visited that page on my localhost:8888/cars.php

Checked in the admin panel - there is a new page.

I created a file import.php

cars.csv is inside addons/csv/

I visited import.php, clicked start. Everything seems to be ok..except it's not, nothing new was added to the database. What I did wrong?

Im running the latest version of couchcms.

Thank you!
A Javascript-based code that redirects to a new page is not always the possible one. I made a new tag for cases where server-side pagination is a necessity, for instance daily-performed tasks with sitemaps, csv export-import etc. Code is supersimple —

Code: Select all
<cms:chase_links base_link=k_template_link>
  <cms:if chase_done >DONE!</cms:if>
</cms:chase_links>


I am sure people can build a good example for a server-side CSV importer as well.
Previous 1 ... 3, 4, 5, 6, 7 Next
63 posts Page 6 of 7
cron