Skip to content

Commit b5a4bd4

Browse files
feat: add cleanup records
1 parent 39d86d1 commit b5a4bd4

File tree

6 files changed

+145
-3
lines changed

6 files changed

+145
-3
lines changed

includes/admin/abstract/class-rop-model-abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function set( $key, $value = '', $refresh = false ) {
9292

9393
$this->data[ $key ] = apply_filters( 'rop_set_key_' . $key, $value );
9494

95-
return update_option( $this->namespace, $this->data );
95+
return update_option( $this->namespace, $this->data, false );
9696
}
9797

9898

includes/admin/class-rop-rest-api.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,20 @@ private function add_account_bluesky( $data ) {
16421642
return $this->response->to_array();
16431643
}
16441644

1645+
/**
1646+
* API method called to cleanup services.
1647+
*
1648+
* @access private
1649+
* @return array<string, mixed>
1650+
*/
1651+
public function cleanup_accounts() {
1652+
$model = new Rop_Services_Model();
1653+
$this->response->set_code( '200' )
1654+
->set_data( $model->cleanup_accounts() );
1655+
1656+
return $this->response->to_array();
1657+
}
1658+
16451659
/**
16461660
* Share API method.
16471661
*

includes/admin/models/class-rop-services-model.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class Rop_Services_Model extends Rop_Model_Abstract {
3737
*/
3838
private $accounts_namespace = 'active_accounts';
3939

40+
/**
41+
* Cleanup account count.
42+
*
43+
* @access private
44+
* @var int $cleanup_account_count
45+
*/
46+
private $cleanup_account_count = 1000;
4047

4148
/**
4249
* Utility method to clear authenticated services.
@@ -520,4 +527,20 @@ public function find_account( $account_id ) {
520527
return false;
521528
}
522529

530+
/**
531+
* Utility method to cleanup authenticated services.
532+
*
533+
* @access public
534+
* @return array<string, mixed>
535+
*/
536+
public function cleanup_accounts() {
537+
$services = $this->get( $this->services_namespace );
538+
539+
if ( count( $services ) > $this->cleanup_account_count ) {
540+
$services = array_slice( $services, -( $this->cleanup_account_count ), null, true );
541+
$this->set( $this->services_namespace, $services );
542+
}
543+
544+
return $services;
545+
}
523546
}

includes/class-rop-i18n.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ public static function get_labels( $key = '' ) {
139139
'upsell_bz_service_body' => __( 'We\'re sorry, %1$s is not available on your plan. Please upgrade to the business plan to unlock all these features and get more traffic.', 'tweet-old-post' ),
140140
'search_account' => __( 'Search account', 'tweet-old-post' ),
141141
'no_account_found' => __( 'No account found for search', 'tweet-old-post' ),
142+
'cleanup_cta' => __( 'Cleanup accounts', 'tweet-old-post' ),
143+
'cleanup_title' => __( 'Clean Up Accounts', 'tweet-old-post' ),
144+
'cleanup_description' => __( 'This will remove older account records and keep only the most recent 1,000 accounts. This helps improve performance and reduce stored data.', 'tweet-old-post' ),
145+
'cleanup_now' => __( 'Cleanup now', 'tweet-old-post' ),
142146
),
143147
'settings' => array(
144148
'yes_text' => __( 'Yes', 'tweet-old-post' ),

vue/src/models/rop_store.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ export default new Vuex.Store({
270270
case 'toggle_tracking':
271271

272272
break
273+
case 'cleanup_accounts':
274+
state.authenticatedServices = stateData;
275+
break;
273276
default:
274277
Vue.$log.error('No state request for ', requestName);
275278
}

vue/src/vue-elements/accounts-tab-panel.vue

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@
8989
</div>
9090
</div>
9191
<div class="column col-12 text-right">
92+
<button
93+
class="btn btn-secondary me-2"
94+
@click="openCleanupModal()"
95+
>
96+
<i
97+
v-if="!is_loading"
98+
class="fa fa-trash"
99+
/>
100+
<i
101+
v-else
102+
class="fa fa-spinner fa-spin"
103+
/>
104+
{{ labels.cleanup_cta }}
105+
</button>
92106
<button
93107
class="btn btn-secondary"
94108
@click="resetAccountData()"
@@ -106,6 +120,32 @@
106120
</div>
107121
</div>
108122
</div>
123+
<div
124+
class="modal rop-cleanup-modal"
125+
:class="cleanupModalClass"
126+
>
127+
<div class="modal-overlay" />
128+
<div class="modal-container">
129+
<div class="modal-header">
130+
<button
131+
class="btn btn-clear float-right"
132+
@click="closeCleanupModal()"
133+
/>
134+
<div class="modal-title h5">
135+
{{ labels.cleanup_title }}
136+
</div>
137+
</div>
138+
<div class="modal-body">
139+
{{ labels.cleanup_description }}
140+
</div>
141+
<div class="modal-footer">
142+
<button
143+
class="btn btn-success"
144+
@click="cleanupAccount()"
145+
>{{ labels.cleanup_now }}</button>
146+
</div>
147+
</div>
148+
</div>
109149
</div>
110150
</template>
111151

@@ -142,7 +182,8 @@
142182
labels: this.$store.state.labels.accounts,
143183
upsell_link: ropApiSettings.upsell_link,
144184
pro_installed: ropApiSettings.pro_installed,
145-
postTimeout: ''
185+
postTimeout: '',
186+
cleanupModal: false,
146187
}
147188
},
148189
computed: {
@@ -189,7 +230,12 @@
189230
},
190231
hasActiveAccountsLimitation: function () {
191232
return !this.pro_installed && this.accountsCount >= 2 && this.checkLicense ;
192-
}
233+
},
234+
cleanupModalClass: function () {
235+
return {
236+
'active': this.cleanupModal === true
237+
}
238+
},
193239
},
194240
mounted: function () {
195241
if (0 === this.is_preloading) {
@@ -228,6 +274,33 @@
228274
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
229275
})
230276
},
277+
openCleanupModal: function() {
278+
this.cleanupModal = true;
279+
},
280+
closeCleanupModal: function() {
281+
this.cleanupModal = false;
282+
},
283+
cleanupAccount: function() {
284+
if (this.is_loading) {
285+
this.$log.warn('Request in progress...Bail');
286+
return;
287+
}
288+
this.is_loading = true;
289+
this.$store.dispatch('fetchAJAXPromise', {
290+
req: 'cleanup_accounts',
291+
data: {}
292+
}).then(response => {
293+
this.is_loading = false;
294+
this.cleanupModal = false;
295+
if (this.$parent.start_status === true) {
296+
// Stop sharing process if enabled.
297+
this.$parent.togglePosting();
298+
}
299+
}, error => {
300+
this.is_loading = false;
301+
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
302+
})
303+
},
231304
filteredAccounts: function(accounts) {
232305
const result = {};
233306
const query = this.searchAccount?.toLowerCase() || '';
@@ -273,6 +346,31 @@
273346
margin-bottom: 15px;
274347
}
275348
349+
#rop_core .rop-cleanup-modal .modal-container{
350+
max-width: 500px;
351+
padding: 25px;
352+
353+
.modal-title, .modal-footer{
354+
text-align: center;
355+
}
356+
.btn-success{
357+
border:none;
358+
background-color:#00a32a;
359+
color: #fff;
360+
padding: 0.5rem 1rem;
361+
height: auto;
362+
display: inline;
363+
}
364+
.btn-success:hover{
365+
background-color:#009528;
366+
}
367+
.modal-body{
368+
font-size: 0.7rem;
369+
margin: 10px 30px;
370+
padding: 0px;
371+
}
372+
}
373+
276374
@media ( max-width: 600px ) {
277375
#rop_core .panel-body .text-gray {
278376
margin-bottom: 10px;

0 commit comments

Comments
 (0)