CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Import tables often left in DB
Pages: [1]

Author Topic: Import tables often left in DB  (Read 1075 times)

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Import tables often left in DB
April 26, 2011, 07:59:50 am
Hey there,

The temporary tables that CiviCRM creates when doing an import (e.g. civicrm_import_job_2a8c063bffbfc176cd19841d5859e95d) are dropped in CRM_Import_Form_Summary::postProcess() which is only called when someone hits done on the final confirmation screen of an import.

That doesn't happen very often as illustrated by the fact that whenever I get ahold of a civicrm database where someone has been using import, I see a lot of these tables.  I'm wondering how we do a better job of deleting import tables that are no longer necessary.

Michael
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Import tables often left in DB
April 26, 2011, 09:14:02 am
Not sure how to fix that, as the table name doesn't contain the date we can't delete it for sure (ie. might be a user doing an import right now).

Would be nice to modify the table name to civicrm_import_{timestamp}_user. As unique, but can be cleaned up.

Was discussing import with changx and CiviCRM-Scalable-Import-Tool and bin/csv/import.php

IMO, the import process should be modified so that the import is split in 3 components


1) the front end that let the user upload+ do the mapping+ verify
(big suggestion, adding a field "source" that you prepopulate with "import {username} {filename}")

2) a new bin/csv/mapimport.php that does the import. basically like bin/csv/import but that does use the map and can define "constant fields" eg contact_type=Individual and group=42

it can be called directly from the cli or from

3) a cron job looks if 1) didn't provide a file to import, imports it and mail the result to the one that submitted it.

I'd love to have an option to import the contacts in error (eg if line 3 has country = UtopiaLand, it would import it without country, tag the contact "incomplete" and add a note "UtopiaLand is not a country"). Much easier to fix when already in civi if that's an odd line, or to advanced search and delete them all the contacts tagged "incomplete" imported by the user today in one go.

Notice how we don't need any temporary tables anymore, and how we could do that by using the existing apis or adding a handful of APIs (eg api.Contact.getDuplicate)

Added benefit, you can run the script from the cron with a low priority, hence not slowing the users because one does an import.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Import tables often left in DB
April 26, 2011, 09:40:56 am

In later versions of CiviCRM (3.4.x) there is code that:

1. deletes the temporary tables periodically (approx with a 0.1% chance, i.e. once every 1000 civicrm urls being invoked)

2. deletes them during upgrades

I could not think of anything smarter.

yes, would be nice to make import "api-able". We just need someone to write the code :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Import tables often left in DB
April 26, 2011, 10:48:41 am
How come is it that whenever I come up with a suggestion, you have already implemented it?  Gets a bit disheartening :)

Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Import tables often left in DB
April 26, 2011, 10:57:26 am

ping me on irc. i've got a long long list of suggestions that you can help implement :P

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Import tables often left in DB
April 26, 2011, 01:40:04 pm
Quote from: Donald Lobo on April 26, 2011, 09:40:56 am

yes, would be nice to make import "api-able". We just need someone to write the code :)

lobo

Think that's a nice starting point : http://civicrm.org/blogs/xavier/api_batch_tools and was discussing with changx today about his tool.
https://github.com/emotive/CiviCRM-Scalable-Import-Tool

To clarify, I don't think that's a good idea to make the import import "api-able", but I want it to be "api-aware". ie. instead of one big monster of a function, split it and have the bolt and nuts accessible throught the api (eg. exposing the field mapping as an entity) or adding a "createMap" action on contact.

When done, that would "only" be a matter of chaining and reusing existing tools, like  bin/csv/import.php, but that the case in general, when everything specific has been developed and added to the common code, that's simply a matter of using the common code ;)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Import tables often left in DB
April 26, 2011, 02:26:49 pm

import has got a fair amount of legacy code and needs to be restructured (we now also have quite a few webtests testing import, so might make it easier to check the new code validates when/if someone writes this)

i blogged about this sometime ago:

http://civicrm.org/blogs/lobo/implementing-batch-import-api

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Re: Import tables often left in DB
April 26, 2011, 06:09:20 pm
Yes Lobo,

Xavier and I are talking about potential solutions that can be implemented to take advantage of both the user interface that my module offers and the potential power his CSV import tool (using API v3).

I think it can be a win win because my tool currently uses API v2 and API v3 will speed things up quite a bit (especially things with location API). In addition, my module can detect if the host system support shell_exec to use the UI as a wrapper to run from PHP CLI, if not just call the API from The web side of things.


Let me know what you think.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Import tables often left in DB
April 26, 2011, 08:27:52 pm

that would be great if we can replace the current import system. We'll have a bunch of import unit tests that u'll can validate on before we merge things

a few comments:

1. make sure things are hookable. So a module can process and do stuff with the contact from other columns in the import file

2. when doing this stuff, consider centralizing the code a lot better than what we have now (since there are other imports: contribution, activity, participant etc)

3. Would be great to combine contribution + contact import in one file (and the others too) rather than the current multi-step process

4. can we schedule this in for 4.1 :) I'll come back with a list of more features/changes we should consider doing

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Import tables often left in DB

This forum was archived on 2017-11-26.