title: Calling to data object function on upload (SilverStripe)
body: <p>I have a DataObject class called <code>AdminUpload</code> that stores two variables: <code>UploadDate</code> (which is always going to bet set to the current date) and <code>Total</code>, which is an int.</p>
  
  <p>The function <code>updateUploads()</code> is called and stores the current date and increments the <code>Total</code> by 1 each time its called.</p>
  
  <pre><code>&lt;?php
  
  class AdminUpload extends DataObject {
  
      private static $db = array(
          'UploadDate' =&gt; 'Date',
          'Total' =&gt; 'int'
      );
  
      // Tell the datagrid what fields to show in the table
      private static $summary_fields = array(
          'ID' =&gt; 'ID',
          'UploadDate' =&gt; 'Current Date',
          'Total' =&gt; 'Version Number'
      );
  
      public function updateUploads(){
          $uploadDate = SS_Datetime::now();
          $this-&gt;UploadDate = $uploadDate;
          $this-&gt;Total++;//increment the value currently stored in the database each time
  
          $this-&gt;write();
      }
  </code></pre>
  
  <p>}</p>
  
  <p>What I want to to is, when someone uploads a new image in the admin view, then the <code>updateCache()</code> function is called during the <code>onAfterWrite()</code> process. I only want to maintain one entry in the database, though, so every time I upload an image, I want to have just one entry in the <code>AdminUpload</code> database table. </p>
  
  <pre><code>public function onAfterWrite(){
          $updateGallery = parent::onAfterWrite();
  
          $adminUploading = AdminUpload::get();
          $adminUploading -&gt; updateUploads();
  
          return $updateGallery;
      }
  </code></pre>
  
  <p>I've never tried to do a function call in SilverStripe like this--it seems simple enough but since I am not going to add a new entry to the database with each call to the updateUploads() function, that's where I'm stuck. Any tips would be helpful...</p>